All GraphQL requests are POST
method request.
Defaults to endpoint of /graphql
.
Because of this, if you make a POST
fetch
request to /graphql
endpoint with the following request, GraphQL will respond with expected payload:
options = { method: 'POST', headers: {'Content-Type':'application/json'}, body: JSON.stringify({ query:` { title } ` }) } fetch('/graphql', options);
Client query can define inputs (arguments).
# query argument variable starts with a $ sign # it is typed query getUnits($ID: String!) { # query argument is passed to the query getUnits(id: $ID) { id name createdDatetime updatedDatetime } }
This would add another field to the request:
options = { method: 'POST', headers: {'Content-Type':'application/json'}, body: JSON.stringify({ query:` { title } ` variables: { // also used for mutation payload "ID": "a731-21" } }) } fetch('/graphql', options);
Client
can request for flexible information it wants from the graph
Backend will have to support all possible fields for query
in case the frontend requests for it (any permutation)
# Mutation mutation submitInput($mutationInput: GraphqlInputType!) { submitInput(input: $mutationInput) { id name inputMetric createdDatetime updatedDatetime # there could be a lot more fields in existence } } # Mutation payload { "input": { "name": "Sam", "id": "abc123" } }