16.8.1 • Published 2 days ago

graphql v16.8.1

Weekly downloads
5,454,986
License
MIT
Repository
github
Last release
2 days ago

GraphQL.js

The JavaScript reference implementation for GraphQL, a query language for APIs created by Facebook.

npm version Build Status Coverage Status

See more complete documentation at https://graphql.org/ and https://graphql.org/graphql-js/.

Looking for help? Find resources from the community.

Getting Started

An overview of GraphQL in general is available in the README for the Specification for GraphQL. That overview describes a simple set of GraphQL examples that exist as tests in this repository. A good way to get started with this repository is to walk through that README and the corresponding tests in parallel.

Using GraphQL.js

Install GraphQL.js from npm

With yarn:

yarn add graphql

or alternatively using npm:

npm install --save graphql

GraphQL.js provides two important capabilities: building a type schema, and serving queries against that type schema.

First, build a GraphQL type schema which maps to your code base.

import {
  graphql,
  GraphQLSchema,
  GraphQLObjectType,
  GraphQLString,
} from 'graphql';

var schema = new GraphQLSchema({
  query: new GraphQLObjectType({
    name: 'RootQueryType',
    fields: {
      hello: {
        type: GraphQLString,
        resolve() {
          return 'world';
        },
      },
    },
  }),
});

This defines a simple schema with one type and one field, that resolves to a fixed value. The resolve function can return a value, a promise, or an array of promises. A more complex example is included in the top level tests directory.

Then, serve the result of a query against that type schema.

var query = '{ hello }';

graphql(schema, query).then(result => {
  // Prints
  // {
  //   data: { hello: "world" }
  // }
  console.log(result);
});

This runs a query fetching the one field defined. The graphql function will first ensure the query is syntactically and semantically valid before executing it, reporting errors otherwise.

var query = '{ boyhowdy }';

graphql(schema, query).then(result => {
  // Prints
  // {
  //   errors: [
  //     { message: 'Cannot query field boyhowdy on RootQueryType',
  //       locations: [ { line: 1, column: 3 } ] }
  //   ]
  // }
  console.log(result);
});

Want to ride the bleeding edge?

The npm branch in this repository is automatically maintained to be the last commit to master to pass all tests, in the same form found on npm. It is recommended to use builds deployed to npm for many reasons, but if you want to use the latest not-yet-released version of graphql-js, you can do so by depending directly on this branch:

npm install graphql@git://github.com/graphql/graphql-js.git#npm

Using in a Browser

GraphQL.js is a general purpose library and can be used both in a Node server and in the browser. As an example, the GraphiQL tool is built with GraphQL.js!

Building a project using GraphQL.js with webpack or rollup should just work and only include the portions of the library you use. This works because GraphQL.js is distributed with both CommonJS (require()) and ESModule (import) files. Ensure that any custom build configurations look for .mjs files!

Contributing

We actively welcome pull requests, learn how to contribute.

Changelog

Changes are tracked as GitHub releases.

License

GraphQL.js is MIT-licensed.

@quiltt/client@withjoy/server-core@withjoy/server-core-testzikix-core@ckmk/nest-library@caravinci/arranger-server@yuants/server@yuants/ui-web@lwtears/admin-common@mahmudhamid/norsani-components@sirclo/nexus@shoptet/graphql@tomasztrebacz/nest-auth-graphql-redis@preply/video@preply/chat@plurall/reader@jahadjs/graphql@jujulego/jill-lutin@jujulego/jill-myr@krishna-kapoor/next-apollo@klicker-uzh/graphql@safis/cms-schema@scentregroup/react-scripts@sprucelabs/spruce-skill@stoplight/cli@igtb-digital/cbxds-digipay-webcomponentsbosagora-dao-sdk-clientbit-bin@courselit/api@borderfreefinancial/qa-revo-new-consumer-sdk@borderfreefinancial/sandbox-revo-new-consumer-sdk@borderfreefinancial/dev-revo-new-consumer-sdk@borderfreefinancial/prod-revo-new-consumer-sdk@borderfreefinancial/dev-revo-consumer-lite-testing1@devopstation/graph@directus-asolole/api@graphqlzero/schema@graphql-hive/cli@balancer-labs/sdk@amygrooove1/smart-order-router-horiza-fork@blockswaplab/cip-sdkbabel-plugin-relay@commercetools-frontend/application-shell@commercetools-frontend/mc-scripts@tinacms/cli@tinacms/graphql@toptal/davinci-engine@truedat/dq@atomist/automation-client@avocad0/sdk@rafaelcalpena/custom-app-client@newskit-render/my-account@requestnetwork/request-node@redwoodjs/codemods@redwoodjs/web@redwoodjs/graphql-server@redwoodjs/internal@redwoodjs/prerender@redwoodjs/structure@redwoodjs/studio@liquiditeam/sdk@sejazipper/layer-client@easy-express/graphqlpratech-middleware-authorizationonemedics-push-webonemedics-push-web-test@userlab/dexterboilerplate-nextjs-apollo-styledc-antdget-graphql-schema-testduely-graphqlginza-queriessureking-uizess-client@darkwolf/graphql-scalars@darkwolf/graphql-validate-directiveresource-centerpadlocks@ticruz38/graphql-codegen-svelte-apolloreact-native-bluetooth2tigen@aasymeonidis/gatsby-plugin-i18ngraphql-kitwebapp-usersufferfest-apitemplate-avenueneo4j-graphql-deepauthzwap-qrcode-frontendzwap_chatbot_guidezwap_chatbot_npm@igloo_cloud/shared-uinestjs-bookstore-mvcneo-ui-template@ablestack/rdg-apollo-mobx-connector@stefancfuchs/apolar-webcrawler@stefancfuchs/firefly-chatbot@graphqlzero/webgraphql-phoenixblowpack@enlibe/cli@fairfx/spend-common
17.0.0-alpha.3

6 months ago

16.8.1

6 months ago

16.8.0

7 months ago

16.7.1

9 months ago

16.7.0

9 months ago

17.0.0-alpha.2

1 year ago

16.6.0

2 years ago

17.0.0-alpha.1

2 years ago

16.5.0

2 years ago

16.4.0

2 years ago

15.8.0

2 years ago

0.0.1-test.1

2 years ago

16.3.0

2 years ago

16.1.0

2 years ago

16.2.0

2 years ago

15.7.0

2 years ago

15.7.2

2 years ago

15.7.1

2 years ago

16.0.0-rc.7

2 years ago

16.0.1

2 years ago

16.0.0

2 years ago

16.0.0-rc.5

2 years ago

16.0.0-rc.6

2 years ago

16.0.0-rc.3

2 years ago

16.0.0-rc.4

2 years ago

15.6.1

2 years ago

15.6.0

2 years ago

15.5.3

3 years ago

16.0.0-rc.2

3 years ago

15.5.2

3 years ago

16.0.0-rc.1

3 years ago

16.0.0-alpha.5

3 years ago

15.5.1

3 years ago

16.0.0-alpha.4

3 years ago

16.0.0-alpha.3

3 years ago

16.0.0-alpha.1

3 years ago

16.0.0-alpha.2

3 years ago

15.5.0

3 years ago

15.4.0

3 years ago

14.7.0

4 years ago

15.3.0

4 years ago

15.2.0

4 years ago

15.1.0

4 years ago

15.0.0

4 years ago

15.0.0-rc.2

4 years ago

14.6.0

4 years ago

15.0.0-rc.1

4 years ago

15.0.0-alpha.2

4 years ago

15.0.0-alpha.1

4 years ago

14.5.8

4 years ago

14.5.7

4 years ago

14.5.6

5 years ago

14.5.5

5 years ago

14.5.4

5 years ago

14.5.3

5 years ago

14.5.2

5 years ago

14.5.1

5 years ago

14.5.0

5 years ago

14.4.2

5 years ago

14.4.1

5 years ago

14.4.0

5 years ago

14.3.1

5 years ago

14.3.0

5 years ago

14.2.1

5 years ago

14.2.0

5 years ago

14.1.1

5 years ago

14.1.0

5 years ago

14.0.2

6 years ago

14.0.1

6 years ago

14.0.0

6 years ago

14.0.0-rc.2

6 years ago

14.0.0-rc.1

6 years ago

0.13.2

6 years ago

0.13.1

6 years ago

0.13.0

6 years ago

0.13.0-rc.1

6 years ago

0.12.3

6 years ago

0.12.2

6 years ago

0.12.1

6 years ago

0.12.0

6 years ago

0.11.7

6 years ago

0.11.6

6 years ago

0.11.5

6 years ago

0.11.4

6 years ago

0.11.3

7 years ago

0.11.2

7 years ago

0.11.1

7 years ago

0.11.0

7 years ago

0.10.5

7 years ago

0.10.4

7 years ago

0.10.3

7 years ago

0.10.2

7 years ago

0.10.1

7 years ago

0.10.0

7 years ago

0.9.6

7 years ago

0.9.5

7 years ago

0.9.4

7 years ago

0.9.3

7 years ago

0.9.2

7 years ago

0.9.1

7 years ago

0.9.0

7 years ago

0.8.2

7 years ago

0.8.1

7 years ago

0.8.0

7 years ago

0.8.0-beta3

7 years ago

0.8.0-beta2

7 years ago

0.8.0-beta1

7 years ago

0.7.2

7 years ago

0.7.1

7 years ago

0.7.0

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.5.0-beta.1

8 years ago

0.4.18

8 years ago

0.4.17

8 years ago

0.4.16

8 years ago

0.4.15

8 years ago

0.4.14

8 years ago

0.4.13

8 years ago

0.4.12

8 years ago

0.4.11

8 years ago

0.4.10

8 years ago

0.4.9

8 years ago

0.4.8

8 years ago

0.4.7

8 years ago

0.4.6

8 years ago

0.4.5

8 years ago

0.4.4

9 years ago

0.4.3

9 years ago

0.4.2

9 years ago

0.4.1

9 years ago

0.4.0

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.12

9 years ago

0.1.11

9 years ago

0.1.10

9 years ago

0.1.9

9 years ago

0.1.8

9 years ago

0.1.7

9 years ago

0.1.6

9 years ago

0.1.5

9 years ago

0.1.4

9 years ago

0.1.3

9 years ago

0.1.2

9 years ago

0.1.1

9 years ago

0.1.0

9 years ago

0.0.2

9 years ago

0.0.1

9 years ago