GraphiQL组件接受
schema
道具:
架构
:GraphQLSchema实例或
null
如果不使用的话。如果
undefined
提供了,GraphiQL将使用fetcher发送内省查询以生成模式。
你可以用
getIntrospectionQuery
要获得完整的内省模式,请获取内省结果,然后使用它来构建模式。
const { getIntrospectionQuery, buildClientSchema } = require('graphql')
const response = await fetch('ENDPOINT_URL', {
method: 'post',
headers: { 'Content-Type': 'application/json' },
body: { query: JSON.stringify(getIntrospectionQuery()) },
})
const introspectionResult = await response.json()
const schema = buildClientSchema(introspectionResult.data)
在呈现组件之前执行此操作,然后作为道具传入架构。如果您的模式不会改变,您也可以将内省结果保存到一个文件中,并使用该文件而不是查询服务器。