- Notifications
You must be signed in to change notification settings - Fork2.1k
A reference implementation of GraphQL for JavaScript
License
graphql/graphql-js
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
The JavaScript reference implementation for GraphQL, a query language for APIs created by Facebook.
See more complete documentation athttps://graphql.org/ andhttps://graphql.org/graphql-js/.
Looking for help? Find resourcesfrom the community.
A general overview of GraphQL is available in theREADME for theSpecification for GraphQL. That overviewdescribes a simple set of GraphQL examples that exist astestsin this repository. A good way to get started with this repository is to walkthrough that README and the corresponding tests in parallel.
Install GraphQL.js from npm
With npm:
npm install --save graphql
or using yarn:
yarn add graphql
GraphQL.js provides two important capabilities: building a type schema andserving queries against that type schema.
First, build a GraphQL type schema which maps to your codebase.
import{graphql,GraphQLSchema,GraphQLObjectType,GraphQLString,}from'graphql';varschema=newGraphQLSchema({query:newGraphQLObjectType({name:'RootQueryType',fields:{hello:{type:GraphQLString,resolve(){return'world';},},},}),});
This defines a simple schema, with one type and one field, that resolvesto a fixed value. Theresolve
function can return a value, a promise,or an array of promises. A more complex example is included in the top-leveltests directory.
Then, serve the result of a query against that type schema.
varsource='{ hello }';graphql({ schema, source}).then((result)=>{// Prints// {// data: { hello: "world" }// }console.log(result);});
This runs a query fetching the one field defined. Thegraphql
function willfirst ensure the query is syntactically and semantically valid before executingit, reporting errors otherwise.
varsource='{ BoyHowdy }';graphql({ schema, source}).then((result)=>{// Prints// {// errors: [// { message: 'Cannot query field BoyHowdy on RootQueryType',// locations: [ { line: 1, column: 3 } ]}// ]// }console.log(result);});
Note: Please don't forget to setNODE_ENV=production
if you are running a production server. It will disable some checks that can be useful during development but will significantly impact performance.
Thenpm
branch in this repository is automatically maintained to be the lastcommit tomain
to pass all tests, in the same form found on npm. It isrecommended to use builds deployed to npm for many reasons, but if you want to usethe latest not-yet-released version of graphql-js, you can do so by dependingdirectly on this branch:
npm install graphql@git://github.com/graphql/graphql-js.git#npm
Each release of GraphQL.js will be accompanied by an experimental release containing support for the@defer
and@stream
directive proposal. We are hoping to get community feedback on these releases before the proposal is accepted into the GraphQL specification. You can use this experimental release of GraphQL.js by adding the following to your project'spackage.json
file.
"graphql": "experimental-stream-defer"
Community feedback on this experimental release is much appreciated and can be provided on theissue created for this purpose.
GraphQL.js is a general-purpose library and can be used both in a Node serverand in the browser. As an example, theGraphiQLtool is built with GraphQL.js!
Building a project using GraphQL.js withwebpack orrollup should just work and only includethe portions of the library you use. This works because GraphQL.js is distributedwith both CommonJS (require()
) and ESModule (import
) files. Ensure that anycustom build configurations look for.mjs
files!
We actively welcome pull requests. Learn how tocontribute.
This repository is managed by EasyCLA. Project participants must sign the free (GraphQL Specification Membership agreement before making a contribution. You only need to do this one time, and it can be signed byindividual contributors or theiremployers.
To initiate the signature process please open a PR against this repo. The EasyCLA bot will block the merge if we still need a membership agreement from you.
You can finddetailed information here. If you have issues, please emailoperations@graphql.org.
If your company benefits from GraphQL and you would like to provide essential financial support for the systems and people that power our community, please also consider membership in theGraphQL Foundation.
Changes are tracked asGitHub releases.
GraphQL.js isMIT-licensed.
GraphQL.JS follows Semantic Versioning (SemVer) for its releases. Our version support policy is as follows:
- Latest Major Version: We provide full support, including bug fixes and security updates, for the latest major version of GraphQL.JS.
- Previous Major Version: We offer feature support for the previous major version for 12 months after the release of the newest major version.This means that for 12 months we can backport features for specification changesif they don't cause any breaking changes. We'll continuesupporting the previous major version with bug and security fixes.
- Older Versions: Versions older than the previous major release are considered unsupported. While the code remains available,we do not actively maintain or provide updates for these versions.One exception to this rule is when the older version has been released < 1 year ago, in that case wewill treat it like the "Previous Major Version".
We do not currently offer a Long-Term Support version of GraphQL.JS. Users are encouraged to upgrade to the latest stable versionto receive the most up-to-date features, performance improvements, and security updates.
We will announce the EOL date for a major version at least 6 months in advance.After a version reaches its EOL, it will no longer receive updates, even for critical security issues.
To assist users in upgrading to newer versions:
- We maintain detailed release notes for each version, highlighting new features, breaking changes, and deprecations.
- Our documentation includes migration guides for moving between major versions.
- Thecommunity forum (Discord channel #graphql-js) is available for users who need additional assistance with upgrades.
We prioritize the security of GraphQL.JS:
- Critical security updates will be applied to both the current and previous major version.
- For versions that have reached EOL, we strongly recommend upgrading to a supported version to receive security updates.
We welcome community contributions for all versions of GraphQL.JS. However, our maintainers will primarily focus on reviewingand merging contributions for supported versions.
About
A reference implementation of GraphQL for JavaScript
Topics
Resources
License
Contributing
Security policy
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.