9.0.2 • Published 23 days ago

graphql-tools v9.0.2

Weekly downloads
2,329,158
License
MIT
Repository
github
Last release
23 days ago

GraphQL-tools: generate and mock GraphQL.js schemas

npm version Build Status Coverage Status Get on Slack

This package provides a few useful ways to create a GraphQL schema:

  1. Use the GraphQL schema language to generate a schema with full support for resolvers, interfaces, unions, and custom scalars. The schema produced is completely compatible with GraphQL.js.
  2. Mock your GraphQL API with fine-grained per-type mocking
  3. Automatically stitch multiple schemas together into one larger API

Documentation

Read the docs.

Binding to HTTP

If you want to bind your JavaScript GraphQL schema to an HTTP server, we recommend using Apollo Server, which supports every popular Node HTTP server library including Express, Koa, Hapi, and more.

JavaScript GraphQL servers are often developed with graphql-tools and apollo-server-express together: One to write the schema and resolver code, and the other to connect it to a web server.

Example

See and edit the live example on Launchpad.

When using graphql-tools, you describe the schema as a GraphQL type language string:

const typeDefs = `
type Author {
  id: ID! # the ! means that every author object _must_ have an id
  firstName: String
  lastName: String
  """
  the list of Posts by this author
  """
  posts: [Post]
}

type Post {
  id: ID!
  title: String
  author: Author
  votes: Int
}

# the schema allows the following query:
type Query {
  posts: [Post]
}

# this schema allows the following mutation:
type Mutation {
  upvotePost (
    postId: ID!
  ): Post
}

# we need to tell the server which types represent the root query
# and root mutation types. We call them RootQuery and RootMutation by convention.
schema {
  query: Query
  mutation: Mutation
}
`;

export default typeDefs;

Then you define resolvers as a nested object that maps type and field names to resolver functions:

const resolvers = {
  Query: {
    posts() {
      return posts;
    },
  },
  Mutation: {
    upvotePost(_, { postId }) {
      const post = find(posts, { id: postId });
      if (!post) {
        throw new Error(`Couldn't find post with id ${postId}`);
      }
      post.votes += 1;
      return post;
    },
  },
  Author: {
    posts(author) {
      return filter(posts, { authorId: author.id });
    },
  },
  Post: {
    author(post) {
      return find(authors, { id: post.authorId });
    },
  },
};

export default resolvers;

At the end, the schema and resolvers are combined using makeExecutableSchema:

import { makeExecutableSchema } from 'graphql-tools';

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

This example has the entire type definition in one string and all resolvers in one file, but you can combine types and resolvers from multiple files and objects, as documented in the modularizing the schema section of the docs.

Contributions

Contributions, issues and feature requests are very welcome. If you are using this package and fixed a bug for yourself, please consider submitting a PR!

@caravinci/arranger-server@tomasztrebacz/nest-auth-graphql-redis@sprucelabs/spruce-skill-server@graphqlzero/schema@atomist/automation-clientgraphql-kitsufferfest-apinestjs-bookstore-mvc@stefancfuchs/apolar-webcrawler@stefancfuchs/firefly-chatbotzeit-graphql@zenofa/apollo-server-adonis@wolox/test-package-nodegraphql-inspector-wolox-node@shindiogo/coremelodi-data@aifedespaix/fdp-apicaoliao-plugin-graphqlreact-paytm-createdcommie-servicegintonicmodule-test-schema@nuragic/apollo-server-express@nuragic/apollo-server-azure-functions@nuragic/apollo-server-koa@nuragic/apollo-server@nuragic/apollo-server-hapi@nuragic/apollo-server-lambda@nuragic/apollo-server-core@nuragic/apollo-server-cloud-functions@nuragic/apollo-server-fastifygamestack@schm-dt/apitn-illuminateanna-graphqlprisma-info-parser@coderich/autograph-server@saeris/apollo-server-nowagrovent_apitemplate-graphql-server@k2s/graphql-validator-directiveharvest-graphql-serviceapollo-server-openfaasregulondb-apiavailability-graphql-apiapollo-micro-graphql@jemini/corehuntnet-server@labsavvyapp/reaction-artodes@artodes/reaction-artodeslec-multitenant-apiapi-envevegraphql-typed-client-minimal@aviosgroup/cbr-client@deity/falcon-magento2-api@deity/falcon-blog-extension@deity/falcon-client@deity/falcon-server@deity/falcon-server-env@deity/falcon-shop-extensiontest-package-nodenest-auth-graphql-redis@wtg/graphile-federation@wong-bejo/apigraphqlizercodex-auth-middlewaresnakatomimyid-backjustt-tyx-newweather-graphql@graphite/apollo-expressjsosoapollo-server-starter@cardano-graphql/ledger@gomoko/coreniouz-api8base@lascelles/monorepo-starter-graphql-api@jujulego/janus-proxysynaptix.jspe-layouts@cameronriu/spotify-graphql@getcaya/prisma-binding@saeon/atlas@xyo-network/api-diviner-nodejsudianeutronpay-wallet-common@dysfunctionl/adonis-grapplegraphql-analyticscompass-eth-db@scrumble/appsync-emulator-serverless@tealess/plugin-graphql@maximiliana/mxa-sharedmembrane-graphqlsubkitzaphycms-serverdcr-graphqldcrcms-serverlec-event-logs-apigraphql-api-gateway
9.0.2

23 days ago

9.0.1

9 months ago

9.0.0

1 year ago

8.3.20

2 years ago

8.3.19

2 years ago

8.3.15

2 years ago

8.3.16

2 years ago

8.3.17

2 years ago

8.3.18

2 years ago

8.3.10

2 years ago

8.3.11

2 years ago

8.3.12

2 years ago

8.3.13

2 years ago

8.3.14

2 years ago

8.3.8

2 years ago

8.3.7

2 years ago

8.3.9

2 years ago

8.3.6

2 years ago

8.3.5

2 years ago

8.3.4

2 years ago

8.2.10

2 years ago

8.2.11

2 years ago

8.2.12

2 years ago

8.2.13

2 years ago

8.3.2

2 years ago

8.3.1

2 years ago

8.3.3

2 years ago

8.3.0

2 years ago

8.2.9

3 years ago

8.2.8

3 years ago

8.2.7

3 years ago

8.2.6

3 years ago

8.2.3

3 years ago

8.2.2

3 years ago

8.2.5

3 years ago

8.2.4

3 years ago

8.2.1

3 years ago

8.2.0

3 years ago

8.1.0

3 years ago

8.0.0

3 years ago

7.0.5

3 years ago

7.0.4

4 years ago

7.0.3

4 years ago

7.0.2

4 years ago

7.0.1

4 years ago

7.0.0

4 years ago

6.2.6

4 years ago

6.2.5

4 years ago

6.2.4

4 years ago

6.2.3

4 years ago

6.2.2

4 years ago

6.2.1

4 years ago

6.2.0

4 years ago

6.1.0

4 years ago

6.0.18

4 years ago

6.0.17

4 years ago

6.0.16

4 years ago

6.0.15

4 years ago

6.0.14

4 years ago

6.0.13

4 years ago

6.0.12

4 years ago

6.0.11

4 years ago

6.0.10

4 years ago

6.0.9

4 years ago

6.0.8

4 years ago

6.0.7

4 years ago

6.0.6

4 years ago

6.0.5

4 years ago

6.0.4

4 years ago

6.0.3

4 years ago

6.0.2

4 years ago

6.0.1

4 years ago

5.0.1-f46fe56.0

4 years ago

6.0.0

4 years ago

5.0.1-76cd870.0

4 years ago

5.0.1-ff37880.0

4 years ago

5.0.1-d77b29b.0

4 years ago

5.0.1-0f4b8cb.0

4 years ago

5.0.1-452401f.0

4 years ago

5.0.1-f25e188.0

4 years ago

5.0.1-2391510.0

4 years ago

5.0.1-cb3f984.0

4 years ago

5.0.1-5547b51.0

4 years ago

5.0.1-64ea73f.0

4 years ago

5.0.1-3f8bb6b.0

4 years ago

5.0.1-01572ab.0

4 years ago

5.0.1-5f98912.0

4 years ago

5.0.1-58915ae.0

4 years ago

5.0.1-10bda52.0

4 years ago

5.0.1-6d0ca21.0

4 years ago

5.0.1-be9317c.0

4 years ago

5.0.1-9707670.0

4 years ago

5.0.1-b50a469.0

4 years ago

5.0.1-ae3ca61.0

4 years ago

5.0.1-dd6f8ef.0

4 years ago

5.0.1-d2d4a78.0

4 years ago

5.0.1-15edde8.0

4 years ago

5.0.1-b836af5.0

4 years ago

5.0.1-4a862f0.0

4 years ago

5.0.1-650e587.0

4 years ago

5.0.1-dea7607.0

4 years ago

5.0.1-4ff24c2.0

4 years ago

5.0.1-a730f98.0

4 years ago

5.0.1-209db82.0

4 years ago

5.0.1-7e45efb.0

4 years ago

5.0.1-cd97f3d.0

4 years ago

5.0.1-d863a61.0

4 years ago

5.0.1-29dbf8b.0

4 years ago

5.0.1-f04f30d.0

4 years ago

5.0.1-2198223.0

4 years ago

5.0.1-b15d793.0

4 years ago

5.0.1-a28434e.0

4 years ago

5.0.1-1426cd2.0

4 years ago

5.0.1-8f4af87.0

4 years ago

5.0.1-b40dea3.0

4 years ago

5.0.1-e3b5c30.0

4 years ago

5.0.1-2194ffc.0

4 years ago

5.0.1-e0f3303.0

4 years ago

5.0.1-cc1dae8.0

4 years ago

5.0.1-73aa21a.0

4 years ago

5.0.1-f381207.0

4 years ago

5.0.1-10a8b6c.0

4 years ago

5.0.1-4bd0e0c.0

4 years ago

5.0.1-52c6bb1.0

4 years ago

5.0.1-cff85b8.0

4 years ago

5.0.1-3c9f82d.0

5 years ago

5.0.1-88f8f2a.0

5 years ago

5.0.1-cf63817.0

5 years ago

5.0.1-9c2ccbe.0

5 years ago

5.0.1-0a0e208.0

5 years ago

5.0.1-4c81062.0

5 years ago

5.0.1-5475b4e.0

5 years ago

5.0.1-353fbbd.0

5 years ago

5.0.1-21ff648.0

5 years ago

5.0.1-fcb74e6.0

5 years ago

5.0.1-02ca401.0

5 years ago

5.0.1-4797d1d.0

5 years ago

5.0.1-31c5d9f.0

5 years ago

5.0.1-3ed5072.0

5 years ago

5.0.1-a4cff7d.0

5 years ago

5.0.1-8a99736.0

5 years ago

5.0.1-25884cd.0

5 years ago

5.0.1-5568e03.0

5 years ago

5.0.1-2ab1687.0

5 years ago

5.0.1-c334147.0

5 years ago

5.0.1-db9aea9.0

5 years ago

5.0.1-3decc20.0

5 years ago

5.0.1-6f2c73b.0

5 years ago

5.0.1-e097305.0

5 years ago

5.0.1-49d5a8c.0

5 years ago

5.0.1-a989e8f.0

5 years ago

5.0.1-1c3d51f.0

5 years ago

5.0.1-4e2d6e8.0

5 years ago

5.0.1-8d3fa47.0

5 years ago

5.0.1-5bad041.0

5 years ago

5.0.1-923a64f.0

5 years ago

5.0.1-2aaf8d2.0

5 years ago

5.0.1-6ff4823.0

5 years ago

5.0.1-6bd6072.0

5 years ago

5.0.1-dc140ab.0

5 years ago

5.0.1-60a1514.0

5 years ago

5.0.1-c4fd839.0

5 years ago

5.0.1-683f684.0

5 years ago

5.0.1-1a70fcd.0

5 years ago

5.0.1-673f89e.0

5 years ago

5.0.1-d5df100.0

5 years ago

5.0.1-f0b83f9.0

5 years ago

5.0.1-60f9da2.0

5 years ago

5.0.1-3cec53a.0

5 years ago

5.0.1-25d7f4c.0

5 years ago

5.0.1-1da2f09.0

5 years ago

5.0.1-5ba4472.0

5 years ago

5.0.1-770e5d7.0

5 years ago

5.0.1-0266a94.0

5 years ago

5.0.1-27d1b77.0

5 years ago

5.0.1-1d0c460.0

5 years ago

5.0.1-23039ef.0

5 years ago

5.0.1-559291b.0

5 years ago

5.0.1-4d18334.0

5 years ago

5.0.1-df679eb.0

5 years ago

5.0.1-f117457.0

5 years ago

5.0.1-04d9545.0

5 years ago

5.0.1-9743451.0

5 years ago

5.0.1-6bd756e.0

5 years ago

5.0.1-4f823bd.0

5 years ago

5.0.1-667754d.0

5 years ago

5.0.1-aa4dedb.0

5 years ago

5.0.1-7f6e89d.0

5 years ago

5.0.1-a61bf99.0

5 years ago

5.0.1-38d7b06.0

5 years ago

5.0.1-4dc0a84.0

5 years ago

5.0.1-325f84d.0

5 years ago

5.0.1-2b66cda.0

5 years ago

5.0.1-9a215b1.0

5 years ago

5.0.1-42c51f2.0

5 years ago

5.0.1-8d9b6b1.0

5 years ago

5.0.1-0fed196.0

5 years ago

5.0.1-ea45c81.0

5 years ago

5.0.1-954a016.0

5 years ago

5.0.1-b0a6f8a.0

5 years ago

5.0.1-9837ea4.0

5 years ago

5.0.1-4b0ebc4.0

5 years ago

5.0.1-98409d6.0

5 years ago

5.0.1-836627f.0

5 years ago

5.0.1-9bc5cf3.0

5 years ago

5.0.1-d839b01.0

5 years ago

5.0.1-86139cb.0

5 years ago

5.0.1-94b86aa.0

5 years ago

5.0.1-589e22d.0

5 years ago

5.0.1-467020c.0

5 years ago

5.0.1-494209a.0

5 years ago

5.0.1-f7650bd.0

5 years ago

5.0.1-579c776.0

5 years ago

5.0.1-26c7e12.0

5 years ago

5.0.1-7f7eaf7.0

5 years ago

5.0.1-729f1d7.0

5 years ago

5.0.1-7111f85.0

5 years ago

5.0.1-bcb7971.0

5 years ago

5.0.1-bf02a16.0

5 years ago

5.0.1-cf5e075.0

5 years ago

5.0.1-27c4ee0.0

5 years ago

5.0.1-190fee1.0

5 years ago

5.0.1-209a2b2.0

5 years ago

5.0.1-f023fe8.0

5 years ago

5.0.1-2837414.0

5 years ago

5.0.1-766e3a9.0

5 years ago

5.0.1-c067539.0

5 years ago

5.0.1-bac1506.0

5 years ago

5.0.1-aba5f79.0

5 years ago

5.0.1-10f6efb.0

5 years ago

5.0.1-9b808fc.0

5 years ago

5.0.1-0efe4de.0

5 years ago

5.0.1-afe7d4a.0

5 years ago

5.0.1-908d646.0

5 years ago

5.0.1-b328890.0

5 years ago

5.0.1-989b692.0

5 years ago

5.0.1-7bcd599.0

5 years ago

5.0.1-f002916.0

5 years ago

5.0.1-b2a30ff.0

5 years ago

5.0.1-939ff0a.0

5 years ago

5.0.1-065f82a.0

5 years ago

5.0.1-6c59e11.0

5 years ago

5.0.1-857bf51.0

5 years ago

5.0.1-f8c0642.0

5 years ago

5.0.1-1ccb078.0

5 years ago

5.0.1-5424ad0.0

5 years ago

5.0.1-d3df728.0

5 years ago

5.0.1-35a8804.0

5 years ago

5.0.1-7413ccc.0

5 years ago

5.0.1-fd9834b.0

5 years ago

5.0.1-6a29acd.0

5 years ago

5.0.1-636f21f.0

5 years ago

5.0.1-edbb49c.0

5 years ago

5.0.1-38bb29b.0

5 years ago

5.0.1-2ffad6d.0

5 years ago

5.0.1-9ab5113.0

5 years ago

5.0.1-6c88fab.0

5 years ago

5.0.1-91366ba.0

5 years ago

5.0.1-54667e7.0

5 years ago

5.0.1-fc155e3.0

5 years ago

5.0.1-7bb31cc.0

5 years ago

5.0.1-1e6783b.0

5 years ago

5.0.1-604516c.0

5 years ago

5.0.1-9e160aa.0

5 years ago

5.0.1-8849db2.0

5 years ago

5.0.1-85f8b9b.0

5 years ago

5.0.1-ece843f.0

5 years ago

5.0.1-693576f.0

5 years ago

5.0.1-5b15807.0

5 years ago

5.0.1-daa06cc.0

5 years ago

5.0.1-f6e332d.0

5 years ago

5.0.1-aa16d1c.0

5 years ago

5.0.1-0df3354.0

5 years ago

5.0.1-ac388a9.0

5 years ago

5.0.1-bb9ec1d.0

5 years ago

5.0.1-bd31804.0

5 years ago

5.0.1-275ca6f.0

5 years ago

5.0.1-ffb435a.0

5 years ago

5.0.1-aedf61d.0

5 years ago

5.0.1-b45fa6e.0

5 years ago

5.0.1-bd68d6c.0

5 years ago

5.0.1-76a881f.0

5 years ago

5.0.1-4542e71.0

5 years ago

5.0.1-a01c016.0

5 years ago

5.0.1-ee6442c.0

5 years ago

5.0.1-1869a41.0

5 years ago

5.0.1-0dad594.0

5 years ago

5.0.1-8944cb5.0

5 years ago

5.0.1-dbc0e7f.0

5 years ago

5.0.1-5bf163e.0

5 years ago

5.0.1-60ac050.0

5 years ago

5.0.1-f365a13.0

5 years ago

5.0.1-2def1b9.0

5 years ago

5.0.1-27b110c.0

5 years ago

5.0.1-b74803d.0

5 years ago

5.0.1-9b6c13d.0

5 years ago

5.0.1-4d5677d.0

5 years ago

5.0.0

5 years ago

4.0.8

5 years ago

5.0.0-rc.4

5 years ago

5.0.0-rc.2

5 years ago

5.0.0-rc.3

5 years ago

5.0.0-alpha.2

5 years ago

5.0.0-alpha.1

5 years ago

5.0.0-alpha.0

5 years ago

4.0.7

5 years ago

4.0.6

5 years ago

4.0.5

5 years ago

5.0.0-rc.1

6 years ago

5.0.0-rc.0

6 years ago

4.0.4

6 years ago

4.0.3

6 years ago

4.0.2

6 years ago

4.0.1

6 years ago

4.0.0

6 years ago

3.1.1

6 years ago

3.1.0

6 years ago

3.0.5

6 years ago

3.0.4

6 years ago

3.0.3

6 years ago

3.0.2

6 years ago

3.0.1

7 years ago

3.0.0

7 years ago

3.0.0-beta.0

7 years ago

3.0.0-alpha.16

7 years ago

3.0.0-alpha.15

7 years ago

2.24.0

7 years ago

3.0.0-alpha.14

7 years ago

3.0.0-alpha.13

7 years ago

3.0.0-alpha.12

7 years ago

3.0.0-alpha.11

7 years ago

2.23.1

7 years ago

2.23.0

7 years ago

2.22.0

7 years ago

3.0.0-alpha.10

7 years ago

3.0.0-alpha.9

7 years ago

2.22.0-alpha.0

7 years ago

3.0.0-alpha.8

7 years ago

3.0.0-alpha.7

7 years ago

3.0.0-alpha.6

7 years ago

3.0.0-alpha.5

7 years ago

3.0.0-alpha.4

7 years ago

3.0.0-alpha.3

7 years ago

2.21.0

7 years ago

2.20.2

7 years ago

2.20.1

7 years ago

3.0.0-alpha.2

7 years ago

3.0.0-alpha.1

7 years ago

2.20.0

7 years ago

2.19.0

7 years ago

2.18.0

7 years ago

2.17.0

7 years ago

2.16.1-launchpad

7 years ago

2.16.0-launchpad

7 years ago

2.16.0

7 years ago

2.15.0

7 years ago

2.14.1

7 years ago

2.15.0-alpha.1

7 years ago

2.14.0

7 years ago

2.13.0

7 years ago

2.12.0-alpha-3

7 years ago

2.12.0-alpha-2

7 years ago

2.12.0-alpha.1

7 years ago

2.12.0

7 years ago

2.11.0

7 years ago

2.11.0-0

7 years ago

2.10.0

7 years ago

2.9.0

7 years ago

2.8.0

7 years ago

2.7.2

7 years ago

2.7.1

7 years ago

2.7.0

7 years ago

2.6.1

7 years ago

2.6.0

7 years ago

2.5.1

7 years ago

2.5.0

7 years ago

2.4.0

7 years ago

2.3.0

7 years ago

2.2.1

7 years ago

2.2.0

7 years ago

2.1.0

7 years ago

2.0.0

7 years ago

2.0.0-alpha.26

7 years ago

2.0.0-alpha.25

7 years ago

2.0.0-alpha.24

7 years ago

2.0.0-alpha.23

7 years ago

2.0.0-alpha.22

7 years ago

2.0.0-alpha.21

7 years ago

1.2.3

7 years ago

2.0.0-alpha.20

7 years ago

2.0.0-alpha.19

7 years ago

2.0.0-alpha.18

7 years ago

2.0.0-alpha.17

7 years ago

2.0.0-alpha.16

7 years ago

2.0.0-alpha.15

7 years ago

2.0.0-alpha.14

7 years ago

2.0.0-alpha.13

7 years ago

2.0.0-alpha.12

7 years ago

2.0.0-alpha.11

7 years ago

2.0.0-alpha.10

7 years ago

1.2.2

7 years ago

2.0.0-alpha.9

7 years ago

2.0.0-alpha.8

7 years ago

2.0.0-alpha.7

7 years ago

2.0.0-alpha.6

7 years ago

2.0.0-alpha.5

7 years ago

2.0.0-alpha.4

7 years ago

2.0.0-alpha.3

7 years ago

2.0.0-alpha.2

7 years ago

2.0.0-alpha.1

7 years ago

1.2.1

7 years ago

1.2.0

7 years ago

1.1.0

7 years ago

1.0.0

7 years ago

0.11.0

8 years ago

0.10.1

8 years ago

0.10.0

8 years ago

0.9.2

8 years ago

0.9.1

8 years ago

0.9.0

8 years ago

0.8.4

8 years ago

0.8.3

8 years ago

0.8.2

8 years ago

0.8.1

8 years ago

0.8.0

8 years ago

0.7.2

8 years ago

0.7.1

8 years ago

0.7.0

8 years ago

0.6.6

8 years ago

0.6.5

8 years ago

0.6.4

8 years ago

0.6.3

8 years ago

0.6.2

8 years ago

0.6.1

8 years ago

0.6.0

8 years ago

0.5.0

8 years ago

0.4.2

8 years ago

0.4.1

8 years ago

0.4.0

8 years ago

0.3.14

8 years ago

0.3.13

9 years ago

0.3.12

9 years ago

0.3.11

9 years ago

0.3.10

9 years ago

0.3.9

9 years ago

0.3.8

9 years ago

0.3.7

9 years ago

0.3.6

9 years ago

0.3.4

9 years ago

0.3.3

9 years ago

0.3.2

9 years ago

0.3.1

9 years ago

0.2.7

9 years ago

0.3.0

9 years ago

0.2.6

9 years ago

0.2.5

9 years ago

0.2.4

9 years ago

0.2.3

9 years ago

0.2.2

9 years ago

0.2.1

9 years ago

0.2.0

9 years ago

0.1.0

9 years ago