Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
512 views
in Technique[技术] by (71.8m points)

javascript - Default GraphQL server string response when no query parameter provided?

Is it possible to hit the root graphQL/ and return a string without specifying a query? Just starting out creating a server, wanted to see if it was possible... doesn't seem so. Seems like you have to at least have a query to start.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If you want it to be graphql specs compatible then this isn't possible ...

From specs execution it must contain a document [with query/mutation]:

A request for execution consists of a few pieces of information:

  • The schema to use, typically solely provided by the GraphQL service.
  • A Document which must contain GraphQL OperationDefinition and may contain FragmentDefinition.
  • ...

From 'Executing Requests' request ...

To execute a request, the executor must have a parsed Document and a selected operation name to run if the document defines multiple operations, otherwise the document is expected to only contain a single operation.

... then one of possible response is an error response, e.g.

{"errors":[{"message":"GraphQL Request must include at least one of those two parameters: "query" or "queryId"","extensions":{"category":"request"}}],"extensions":{"debug":[]}}

... if you don't care ...

about strict graphql specs ... and taking assumption that probably nobody needs[/will use seriously possibly error] this response (not tools required introspection) ... you can return even html (not json) 'hello, read docs' content.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...