Implement multiple interfaces in graphql

冷暖自知 提交于 2020-01-03 19:16:20

问题


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

{
  "scripts": {
    "relay": "relay-compiler --src ./ --schema schema.graphqls"
  },
  "dependencies": {
    "react-relay": "1.5.0"
  },
  "devDependencies": {
    "relay-compiler": "1.5.0"
  }
}

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
}`;

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?


回答1:


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


来源:https://stackoverflow.com/questions/49521575/implement-multiple-interfaces-in-graphql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!