Skip to content

Compiler plugin that supports GraphQL files in Meteor

License

Notifications You must be signed in to change notification settings

Swydo/meteor-graphql

This branch is 1 commit ahead of, 2 commits behind master.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

28d4497 · Mar 29, 2020

History

84 Commits
Feb 21, 2018
Mar 25, 2017
Feb 21, 2018
Jun 25, 2019
Dec 19, 2017
Mar 25, 2017
Dec 19, 2017
Dec 19, 2017
Oct 15, 2018
Mar 29, 2020
Mar 25, 2017

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

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published