Implement multiple interfaces in graphql

2019-07-17 06:33发布

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条回答
够拽才男人
2楼-- · 2019-07-17 06:55

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
查看更多
登录 后发表回答