{"componentChunkName":"component---src-templates-doc-tsx","path":"/learn/","result":{"data":{"doc":{"frontmatter":{"title":"GraphQL 入门","heroText":null,"date":null,"permalink":"/learn/","byline":null,"guestBio":null,"sublinks":null,"layout":"docs","tags":null},"id":"0ee54be6-1720-5a1e-8ece-fb979b16dd62","rawMarkdownBody":"\n> 在接下来的一系列文章中，我们会了解 GraphQL 是什么，它是如何运作以及如何使用它。在找如何搭建 GraphQL 服务的文档？这有一些类库可以帮你用[多种不同语言](/code/)实现 GraphQL。通过实用教程深入学习体验，请访问 [How to GraphQL](https://www.howtographql.com) 全栈教程网站。我们还与 edX 合作创建了免费的在线课程，[探索 GraphQL：一种用于 API 的查询语言](https://www.edx.org/course/exploring-graphql-a-query-language-for-apis)。\n\nGraphQL 是一个用于 API 的查询语言，是一个使用基于类型系统来执行查询的服务端运行时（类型系统由你的数据定义）。GraphQL 并没有和任何特定数据库或者存储引擎绑定，而是依靠你现有的代码和数据支撑。\n\n一个 GraphQL 服务是通过定义类型和类型上的字段来创建的，然后给每个类型上的每个字段提供解析函数。例如，一个 GraphQL 服务告诉我们当前登录用户是 `me`，这个用户的名称可能像这样：\n\n```graphql\ntype Query {\n  me: User\n}\n\ntype User {\n  id: ID\n  name: String\n}\n```\n\n一并的还有每个类型上字段的解析函数：\n\n```js\nfunction Query_me(request) {\n  return request.auth.user;\n}\n\nfunction User_name(user) {\n  return user.getName();\n}\n```\n\n一旦一个 GraphQL 服务运行起来（通常在 web 服务的一个 URL 上），它就能接收 GraphQL 查询，并验证和执行。接收到的查询首先会被检查确保它只引用了已定义的类型和字段，然后运行指定的解析函数来生成结果。\n\n例如这个查询：\n\n```graphql\n{\n  me {\n    name\n  }\n}\n```\n\n会产生这样的JSON结果：\n\n```json\n{\n  \"me\": {\n    \"name\": \"Luke Skywalker\"\n  }\n}\n```\n\n在这系列文章中，我们会学习更多关于 GraphQL 的知识，包括查询语言、类型系统、GraphQL 服务的工作原理以及使用 GraphQL 解决常见问题的最佳实践。\n"},"nextDoc":{"frontmatter":{"title":"查询和变更","permalink":"/learn/queries/"}}},"pageContext":{"permalink":"/learn/","nextPermalink":"/learn/queries/","sideBarData":[{"name":"学习","links":[{"fileAbsolutePath":"/builds/bootsite/graphql.bootcss.com/src/content/learn/Introduction.md","parent":{"relativeDirectory":"learn","sourceInstanceName":"content"},"frontmatter":{"title":"GraphQL 入门","permalink":"/learn/","next":"/learn/queries/","category":"学习","sublinks":null,"sidebarTitle":"入门","date":null,"tags":null},"id":"0ee54be6-1720-5a1e-8ece-fb979b16dd62"},{"fileAbsolutePath":"/builds/bootsite/graphql.bootcss.com/src/content/learn/Learn-Queries.md","parent":{"relativeDirectory":"learn","sourceInstanceName":"content"},"frontmatter":{"title":"查询和变更","permalink":"/learn/queries/","next":"/learn/schema/","category":"学习","sublinks":"字段（Fields）,参数（Arguments）,别名（Aliases）,片段（Fragments）,操作名称（Operation Name）,变量（Variables）,指令（Directives）,变更（Mutations）,内联片段（Inline Fragments）","sidebarTitle":null,"date":null,"tags":null},"id":"c9eaae87-7af4-53d1-8d22-dcc357cf9ebd"},{"fileAbsolutePath":"/builds/bootsite/graphql.bootcss.com/src/content/learn/Learn-Schema.md","parent":{"relativeDirectory":"learn","sourceInstanceName":"content"},"frontmatter":{"title":"Schema 和类型","permalink":"/learn/schema/","next":"/learn/validation/","category":"学习","sublinks":"类型系统（Type System）,类型语言（Type Language）,对象类型和字段（Object Types and Fields）,参数（Arguments）,查询和变更类型（The Query and Mutation Types）,标量类型（Scalar Types）,枚举类型（Enumeration Types）,列表和非空（Lists and Non-Null）,接口（Interfaces）,联合类型（Union Types）,输入类型（Input Types）","sidebarTitle":null,"date":null,"tags":null},"id":"4654c5aa-cb5a-5d3d-a8f2-aa745442f191"},{"fileAbsolutePath":"/builds/bootsite/graphql.bootcss.com/src/content/learn/Learn-Validation.md","parent":{"relativeDirectory":"learn","sourceInstanceName":"content"},"frontmatter":{"title":"验证","permalink":"/learn/validation/","next":"/learn/execution/","category":"学习","sublinks":null,"sidebarTitle":null,"date":null,"tags":null},"id":"ace84a16-5096-56c9-935d-21d2b906af78"},{"fileAbsolutePath":"/builds/bootsite/graphql.bootcss.com/src/content/learn/Learn-Execution.md","parent":{"relativeDirectory":"learn","sourceInstanceName":"content"},"frontmatter":{"title":"执行","permalink":"/learn/execution/","next":"/learn/introspection/","category":"学习","sublinks":null,"sidebarTitle":null,"date":null,"tags":null},"id":"904f9702-a5a0-5df0-b1eb-2da36f776561"},{"fileAbsolutePath":"/builds/bootsite/graphql.bootcss.com/src/content/learn/Learn-Introspection.md","parent":{"relativeDirectory":"learn","sourceInstanceName":"content"},"frontmatter":{"title":"内省","permalink":"/learn/introspection/","next":"/learn/best-practices/","category":"学习","sublinks":null,"sidebarTitle":null,"date":null,"tags":null},"id":"d1d17514-cd00-53be-a0bb-4d88017aa9e5"}]},{"name":"最佳实践","links":[{"fileAbsolutePath":"/builds/bootsite/graphql.bootcss.com/src/content/learn/BestPractice-Introduction.md","parent":{"relativeDirectory":"learn","sourceInstanceName":"content"},"frontmatter":{"title":"GraphQL 最佳实践","permalink":"/learn/best-practices/","next":"/learn/thinking-in-graphs/","category":"最佳实践","sublinks":null,"sidebarTitle":"介绍","date":null,"tags":null},"id":"b4a7bf97-771a-54bd-8e41-c3e1ba12b191"},{"fileAbsolutePath":"/builds/bootsite/graphql.bootcss.com/src/content/learn/BestPractice-ThinkingInGraphs.md","parent":{"relativeDirectory":"learn","sourceInstanceName":"content"},"frontmatter":{"title":"关于 Graphs 的思考","permalink":"/learn/thinking-in-graphs/","next":"/learn/serving-over-http/","category":"最佳实践","sublinks":null,"sidebarTitle":null,"date":null,"tags":null},"id":"fe550746-7613-5080-babd-871740663112"},{"fileAbsolutePath":"/builds/bootsite/graphql.bootcss.com/src/content/learn/BestPractice-ServingOverHTTP.md","parent":{"relativeDirectory":"learn","sourceInstanceName":"content"},"frontmatter":{"title":"通过 HTTP 提供服务","permalink":"/learn/serving-over-http/","next":"/learn/authorization/","category":"最佳实践","sublinks":null,"sidebarTitle":null,"date":null,"tags":null},"id":"b4583332-4a60-5d2f-b64f-040799bedc90"},{"fileAbsolutePath":"/builds/bootsite/graphql.bootcss.com/src/content/learn/BestPractice-Authorization.md","parent":{"relativeDirectory":"learn","sourceInstanceName":"content"},"frontmatter":{"title":"授权","permalink":"/learn/authorization/","next":"/learn/pagination/","category":"最佳实践","sublinks":null,"sidebarTitle":null,"date":null,"tags":null},"id":"d6117d7d-19c7-5725-bb04-6b0ecd348842"},{"fileAbsolutePath":"/builds/bootsite/graphql.bootcss.com/src/content/learn/BestPractice-Pagination.md","parent":{"relativeDirectory":"learn","sourceInstanceName":"content"},"frontmatter":{"title":"分页","permalink":"/learn/pagination/","next":"/learn/global-object-identification/","category":"最佳实践","sublinks":null,"sidebarTitle":null,"date":null,"tags":null},"id":"9cfe3316-94bd-52b5-920a-d6778fe0c348"},{"fileAbsolutePath":"/builds/bootsite/graphql.bootcss.com/src/content/learn/BestPractice-NodeInterface.md","parent":{"relativeDirectory":"learn","sourceInstanceName":"content"},"frontmatter":{"title":"全局对象识别","permalink":"/learn/global-object-identification/","next":"/learn/caching/","category":"最佳实践","sublinks":null,"sidebarTitle":null,"date":null,"tags":null},"id":"1c64bf71-985a-5271-b388-b529ac2270df"},{"fileAbsolutePath":"/builds/bootsite/graphql.bootcss.com/src/content/learn/BestPractice-Caching.md","parent":{"relativeDirectory":"learn","sourceInstanceName":"content"},"frontmatter":{"title":"缓存","permalink":"/learn/caching/","next":null,"category":"最佳实践","sublinks":null,"sidebarTitle":null,"date":null,"tags":null},"id":"0988bfe0-290a-5f2f-89d9-13df946179f9"}]}],"sourcePath":"src/content/learn/Introduction.md"}},"staticQueryHashes":["1581580458","4162432391"]}