Meteor GraphQL
This is fork of https://github.com/swydo/meteor-graphql. The original package is not maintained anymore. We created this to create compatibility with Meteor 3.
Compiler plugin that supports GraphQL files in Meteor
Installation
meteor add compat:graphql
Usage
Queries
# query.grahql query getPerson ($id: ID!) { person(id: $id) { name email } }
1import query from './query.graphql'; 2 3// See https://github.com/apollographql/apollo-client for setup 4const client = new ApolloClient(); 5 6// The query is parsed and can be directly passed to the Apollo Client 7client.query({ query }).then(console.log);
Multiple queries in one file
It's also possible to define multiple queries in one file:
# queries.grahql query foo { baz } query bar { baz }
1import { foo, bar } from './queries.graphql'; 2 3const client = new ApolloClient(); 4 5client.query({ query: foo }).then(console.log);
Schemas
You can also import your main schema and pass it directly to makeExecutableSchema
.
# schema.graphql """ This is a description of a Person This will show up in GraphiQL """ type Person { id: ID! name: String email: String } type Query { person(id!): Person }
1import { makeExecutableSchema } from 'graphql-tools'; 2 3import typeDefs from './schema.graphql'; // No need to parse it! 4import resolvers from './resolvers'; 5 6const schema = makeExecutableSchema({ 7 typeDefs, 8 resolvers, 9});
Importing .graphql files in other .graphql files
The cool thing is that you can use import comments, that will import all definitions from another file:
#import "./personSchema.graphql" type Query { # It will recognize the Person type from the personSchema.graphql file person(id): Person }
Extensions
We recommend to always use .graphql
, but also .graphqls
and .gql
files are supported.
Benefits
There are some good reasons to use .graphql
files instead of the inline syntax:
- Good highlighting by GitHub and your IDE
- No need to manually parse strings with graphql-tag
- Small performance gain because queries and schemas are parsed ahead of time
- The GraphQL Configuration Protocol will support
.graphql
files out of the box - Works with babel-plugin-inline-import
Sponsor
Want to work with Meteor and GraphQL? Join the team!