If I define a fragment inside the schema I pass to the server, it seems to parse but I can't access it from graphiql later. Is there a way to pass predefined fragments to the server so that a client can use these in queries?
server.js
server.use('/graphql', bodyParser.json(), graphqlExpress(request => ({
schema,
//context: context(request.headers, process.env),
})));
schema.js
type Customer {
details: Contact!
addresses: [Address]!
}
# although this will parse, it doesn't seem to be referenceable in GraphiQL
fragment addressLines on AddressFields {
address1
address2
city
region
country
postal_code
}
extend type Query {
customers(first: Int = 0, next: Int = 50): [Customer]
customer(id: Int!): Customer
}
GraphQL does not support including fragments in schema definitions. Fragments have to be part of the query document that is sent to the server as part of the GraphQL request.
That's correct - there's no way currently to define a fragment on the server side in GraphQL itself. We might want to add an error when people try to do that though.
Most helpful comment
GraphQL does not support including fragments in schema definitions. Fragments have to be part of the query document that is sent to the server as part of the GraphQL request.