在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:graphql/graphql-js开源软件地址:https://github.com/graphql/graphql-js开源编程语言:TypeScript 98.8%开源软件介绍:GraphQL.jsThe JavaScript reference implementation for GraphQL, a query language for APIs created by Facebook. See more complete documentation at https://graphql.org/ and https://graphql.org/graphql-js/. Looking for help? Find resources from the community. Getting StartedA general overview of GraphQL 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.jsInstall 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 and serving queries against that type schema. First, build a GraphQL type schema which maps to your codebase. 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 Then, serve the result of a query against that type schema. var source = '{ hello }';
graphql({ schema, source }).then((result) => {
// Prints
// {
// data: { hello: "world" }
// }
console.log(result);
}); This runs a query fetching the one field defined. The var source = '{ 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 set Want to ride the bleeding edge?The
Experimental featuresEach release of GraphQL.js will be accompanied by an experimental release containing support for the
Community feedback on this experimental release is much appreciated and can be provided on the issue created for this purpose. Using in a BrowserGraphQL.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 ( ContributingWe actively welcome pull requests. Learn how to contribute. 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 by individual contributors or their employers. 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 find detailed information here. If you have issues, please email [email protected]. 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 the GraphQL Foundation. ChangelogChanges are tracked as GitHub releases. LicenseGraphQL.js is MIT-licensed. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论