strapi/docs/.vuepress/dist/assets/js/12.124227d1.js

1 line
16 KiB
JavaScript
Raw Normal View History

2018-10-05 17:24:17 +02:00
(window.webpackJsonp=window.webpackJsonp||[]).push([[12],{227:function(t,s,a){"use strict";a.r(s);var n=a(0),e=Object(n.a)({},function(){this.$createElement;this._self._c;return this._m(0)},[function(){var t=this,s=t.$createElement,a=t._self._c||s;return a("div",{staticClass:"content"},[a("h1",{attrs:{id:"graphql"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#graphql","aria-hidden":"true"}},[t._v("#")]),t._v(" GraphQL")]),t._v(" "),a("p",[t._v("GraphQL is a data querying language that allows you to execute complex nested\nrequests between your clients and server applications.")]),t._v(" "),a("h2",{attrs:{id:"configuration"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#configuration","aria-hidden":"true"}},[t._v("#")]),t._v(" Configuration")]),t._v(" "),a("p",[t._v("By default, GraphQL is enabled and the HTTP endpoint is "),a("code",[t._v("/graphql")]),t._v(".\nYou can override this settings in the "),a("code",[t._v("./config/general.json")]),t._v(" file.")]),t._v(" "),a("div",{staticClass:"language-js extra-class"},[a("pre",{pre:!0,attrs:{class:"language-js"}},[a("code",[a("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"graphql"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"enabled"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token boolean"}},[t._v("true")]),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"route"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token string"}},[t._v('"/graphql"')]),t._v("\n "),a("span",{attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),a("span",{attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),a("p",[t._v("Options:")]),t._v(" "),a("ul",[a("li",[a("code",[t._v("enabled")]),t._v(" (boolean): Enabled or disabled GraphQL.")]),t._v(" "),a("li",[a("code",[t._v("route")]),t._v(" (string): Change GraphQL endpoint.")])]),t._v(" "),a("p",[t._v("Note: If GraphQL is disabled, the GraphQL global variable is not exposed.")]),t._v(" "),a("h2",{attrs:{id:"execute-simple-query"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#execute-simple-query","aria-hidden":"true"}},[t._v("#")]),t._v(" Execute simple query")]),t._v(" "),a("h3",{attrs:{id:"programmatically"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#programmatically","aria-hidden":"true"}},[t._v("#")]),t._v(" Programmatically")]),t._v(" "),a("p",[t._v("Strapi takes over GraphQL natively. We added a function called "),a("code",[t._v("query")]),t._v(" to execute\nyour query without given as a parameters the GraphQL schemas each time.")]),t._v(" "),a("p",[t._v("An example of how to use "),a("code",[t._v("query")]),t._v(" function:")]),t._v(" "),a("div",{staticClass:"language-js extra-class"},[a("pre",{pre:!0,attrs:{class:"language-js"}},[a("code",[a("span",{attrs:{class:"token comment"}},[t._v("// Build your query")]),t._v("\n"),a("span",{attrs:{class:"token keyword"}},[t._v("const")]),t._v(" query "),a("span",{attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),a("span",{attrs:{class:"token string"}},[t._v("'{ users{firstName lastName posts{title}} }'")]),a("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),a("span",{attrs:{class:"token comment"}},[t._v("// Execute the query")]),t._v("\ngraphql"),a("span",{attrs:{class:"token punctuation"}},[t._v(".")]),a("span",{attrs:{class:"token function"}},[t._v("query")]),a("span",{attrs:{class:"token punctuation"}},[t._v("(")]),t._v("query"),a("span",{attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),a("span",{attrs:{class:"token punctuation"}},[t._v(".")]),a("span",{attrs:{class:"token function"}},[t._v("then")]),a("span",{attrs:{class:"token punctuation"}},[t._v("(")]),a("span",{attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),a("span",{a