Skip to content

Compiler plugin that supports GraphQL files in Meteor

License

Notifications You must be signed in to change notification settings

nathanschwarz/meteor-graphql

 
 

Repository files navigation

Meteor GraphQL

Compiler plugin that supports GraphQL files in Meteor

Build Status Greenkeeper badge

Installation

meteor add swydo:graphql

Usage

Queries

# query.grahql
query getPerson ($id: ID!) {
  person(id: $id) {
    name
    email
  }
}
import query from './query.graphql';

// See https://github.com/apollographql/apollo-client for setup
const client = new ApolloClient();

// The query is parsed and can be directly passed to the Apollo Client
client.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
}
import { foo, bar } from './queries.graphql';

const client = new ApolloClient();

client.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
}
import { makeExecutableSchema } from 'graphql-tools';

import typeDefs from './schema.graphql'; // No need to parse it!
import resolvers from './resolvers';

const schema = makeExecutableSchema({
  typeDefs,
  resolvers,
});

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:

Sponsor

Swydo

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

About

Compiler plugin that supports GraphQL files in Meteor

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%