在graphql中实现多个接口 [英] Implement multiple interfaces in graphql
本文介绍了在graphql中实现多个接口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用中继编译器,但不允许我使用具有多个接口的类型来编译模式.我做了一个小测试项目:
I am using the relay compiler and it is not letting me compile a schema with a type that implements multiple interfaces. I made a small test project:
package.json
package.json
{
"scripts": {
"relay": "relay-compiler --src ./ --schema schema.graphqls"
},
"dependencies": {
"react-relay": "1.5.0"
},
"devDependencies": {
"relay-compiler": "1.5.0"
}
}
schema.graphqls
schema.graphqls
interface First {
a: String
}
interface Second {
b: String
}
type Something implements First, Second {
a: String
b: String
}
test.js
import { graphql } from "react-relay";
graphql`fragment Test_item on Something {
a
b
}`;
如果使用npm run relay运行此程序(在npm安装之后),则会收到错误消息:
If you run this with npm run relay (after npm install) you get the error:
Error: Error loading schema. Expected the schema to be a .graphql or a .json
file, describing your GraphQL server's API. Error detail:
GraphQLError: Syntax Error: Unexpected Name "Second"
有任何想法为什么会发生这种情况?
Any ideas why this is happening?
推荐答案
对于多个接口,您应该使用&号代替逗号.参见此处: http://facebook.github.io/graphql/draft/#sec-界面
You should use an ampersand instead of a comma for multiple interfaces. See here: http://facebook.github.io/graphql/draft/#sec-Interfaces
type Something implements First & Second
这篇关于在graphql中实现多个接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文