在graphql中实现多个接口

Pio*_*otr 3 relay reactjs graphql relaymodern

我正在使用中继编译器,它不允许我编译具有实现多个接口的类型的模式.我做了一个小测试项目:

的package.json

{
  "scripts": {
    "relay": "relay-compiler --src ./ --schema schema.graphqls"
  },
  "dependencies": {
    "react-relay": "1.5.0"
  },
  "devDependencies": {
    "relay-compiler": "1.5.0"
  }
}
Run Code Online (Sandbox Code Playgroud)

schema.graphqls

interface First {
    a: String
}

interface Second {
    b: String
}

type Something implements First, Second {
    a: String
    b: String
}
Run Code Online (Sandbox Code Playgroud)

test.js

import { graphql } from "react-relay";

graphql`fragment Test_item on Something {
    a
    b
}`;
Run Code Online (Sandbox Code Playgroud)

如果你用npm run relay运行它(在npm install之后),你会得到错误:

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"
Run Code Online (Sandbox Code Playgroud)

任何想法为什么会这样?

cel*_*ide 7

您应该使用&符号而不是逗号来表示多个接口.见这里:http://facebook.github.io/graphql/draft/#sec-Interfaces

type Something implements First & Second
Run Code Online (Sandbox Code Playgroud)