Questions tagged [graphql]

GraphQL is an API technology designed to describe the complex, nested data dependencies of modern web applications. It is often considered an alternative to SOAP or REST

GraphQL is a query language for APIs and a runtime for fulfilling those queries with your existing data. GraphQL provides a complete and understandable description of the data in your API, gives clients the power to ask for exactly what they need and nothing more, makes it easier to evolve APIs over time, and enables powerful developer tools.

There are GraphQL implementations in almost every server-side language, and powerful clients for most UI platforms.

20808 questions
88
votes
2 answers

Shouldn't the login be a Query in GraphQL?

In the tutorial on GraphQL authentication, the login is a Mutation: type Mutation { post(url: String!, description: String!): Link! signup(email: String!, password: String!, name: String!): AuthPayload login(email: String!, password: String!):…
Anna B
  • 5,997
  • 5
  • 40
  • 52
86
votes
3 answers

How do I add a description to a field in "GraphQL schema language"

I have a graphql schema, a fragment of which looks like this: type User { username: String! password: String! } In graphiql, there is a description field, but it always says "self-descriptive". How do I add descriptions to the schema?
derekdreery
  • 3,860
  • 4
  • 29
  • 38
83
votes
15 answers

GraphQL gql Syntax Error: Expected Name, found }

I'm attempting to set up Apollo GraphQL support in a new React project, but when I try to compile a query using gql I keep receiving the error: Syntax Error: Expected Name, found } This is generated by the following code: import gql from…
Nathan
  • 1,897
  • 2
  • 15
  • 16
82
votes
5 answers

Firebase & GraphQL

Does anyone have any experience with GraphQL and Firebase? I figure one would place the firebase calls in the resolver of the relevant field, passing some variable from the props of the component into the arguments of the query. How can we insert…
omgj
  • 1,369
  • 3
  • 12
  • 18
78
votes
1 answer

Field \"me\" of type \"User\" must have a selection of subfields

Hi I am trying to learn GraphQL language. I have below snippet of code. // Welcome to Launchpad! // Log in to edit and save pads, run queries in GraphiQL on the right. // Click "Download" above to get a zip with a standalone Node.js server. // See…
N Sharma
  • 33,489
  • 95
  • 256
  • 444
78
votes
4 answers

Can a GraphQL input type inherit from another type or interface?

Is it possible to use inheritance with GraphQL input types? Something like that (this, of course, doesn't work with input types): interface UserInputInterface { firstName: String lastName: String } input UserInput implements UserInputInterface…
kyrisu
  • 4,541
  • 10
  • 43
  • 66
78
votes
8 answers

Document a GraphQL API

With REST we can use Swagger, RAML or other technologies to document our API and generate an HTML documentation that our consumers can read without any need of interaction with the servers. Does something similar exist for GraphQL? Is there any way…
Francisco Canela
  • 1,084
  • 1
  • 7
  • 14
77
votes
2 answers

What is the point of naming queries and mutations in GraphQL?

Pardon the naive question, but I've looked all over for the answer and all I've found is either vague or makes no sense to me. Take this example from the GraphQL spec: query getZuckProfile($devicePicSize: Int) { user(id: 4) { id name …
Nolan
  • 2,209
  • 3
  • 18
  • 20
76
votes
2 answers

Apollo GraphQL React - how to query on click?

In the Apollo React docs http://dev.apollodata.com/react/queries.html#basics there are examples of fetching automatically when the component is shown, but I'd like to run a query when a button is clicked. I see an example to "re"fetch a query when a…
atkayla
  • 8,143
  • 17
  • 72
  • 132
75
votes
2 answers

How to add default values to input arguments in graphql

I have this input type and I would like to add a default Value to one of the fields. I want to add 0 to the value field inside the ExampleInput. type ExampleType { value: Int another: String } type Mutation { example(input: ExampleInput):…
Adolfo
  • 1,315
  • 2
  • 14
  • 22
75
votes
5 answers

GraphQL Error field type must be Input Type but got:

Here is the mutation: const createNotebook = mutationWithClientMutationId ({ name: 'CreateNotebook', inputFields: { token: { type: GraphQLString, }, details: { type: NotebookDetails, …
lee huang
  • 1,209
  • 1
  • 12
  • 23
74
votes
9 answers

graphqlHTTP is not a function

Here is my simple graphql express app const express = require('express'); const graphqlHTTP = require('express-graphql'); const app = express(); app.use( '/graphql', graphqlHTTP({ graphiql: true, }) ); app.listen(4000, () => { …
Sachin Titus
  • 1,960
  • 3
  • 23
  • 41
74
votes
3 answers

Handling errors with react-apollo useMutation hook

I have been trying to get my head around this problem but haven't found a strong answer to it. I am trying to execute a login mutation using the useMutation hook. TLDR; I want to know what exactly is the difference between the onError passed in…
d_bhatnagar
  • 1,419
  • 1
  • 12
  • 20
74
votes
2 answers

OData vs GraphQL

Is there a good comparison of GraphQL & OData in terms of performance, developers usability, community, etc.. All articles that I find in the Internet are very bias. What would be the best way to return a big bulky JSON or binary data?
Yar0myr
  • 757
  • 1
  • 6
  • 4
73
votes
4 answers

How do you extend types in GraphQL?

For example, a Pet is an Animal with an owner and name. type Animal { species: String } type Pet extends Animal { owner: Owner name: String }
atkayla
  • 8,143
  • 17
  • 72
  • 132