Write GraphQL queries as objects instead of strings
This is a better implementation of the GraphQL query API via NodeJS, created as a wrapper of Got. It works like a transpiler, with a built in HTTPRequest Client (Got), allowing you to write your GraphQL queries as Javascript Objects instead of strings.
Built because manipulating strings is a real pain.
GotQL is a better interface for GraphQL queries. It provides a way for developers to run queries using JSON instead of strings. Which is a way more usable data format than the string itself.
Both gotql.query and gotql.mutation accept an optional user option object with the following API:
Type: object
Description: The option object with the following properties.
errorStatusCode: Default HTTP status code to be returned on error
Type: number
headers: Additional headers to be sent
Type: object, in the form of [headerName: string]: headerValue: string
gotInstance: Customized Got instance to be used when calling the endpoint
Type: got. Internally this will be called as got.post(prependHttp(endPoint), gotPayload)
useHttp2: Boolean defining if the call should be made using HTTP2, defaults to false (see release 11 of got)
Type: boolean
Note: GotQL uses debug internally as default debugger, so you can set debug levels by setting the DEBUG environment variable. These are the current levels:
gotql:info
gotql:info:parser
gotql:info:runner
gotql:errors
Returns
All methods return a string like this:
constresponse='query { test { name args } }'
The JSON query format
The JSON format gotQL uses is a simple and intuitive description based on the anatomy of a GraphQL query blog post.
Enum or literal values should not be escaped, to do that, GotQL has a helper called literal which can be used to tell the query that value will not be escaped:
If literal is omitted, or if escape is set to true, the output would be:
query{users(type: "internal"){ name age}}
Note: Variables such as described here will not be recognized. If the arg object is not an [argName]: value, variables will not pass through the definition check (GotQL warns if a variable is not declared but used on operation).
Contributing to this project
Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.
请发表评论