compat:graphql

v2.0.0Published 8 months ago

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

Build Status Greenkeeper badge

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:

Want to work with Meteor and GraphQL? Join the team!