Implement multiple interfaces in graphql
Asked Answered
G

1

4

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?

Gyro answered 27/3, 2018 at 20:6 Comment(0)
H
9

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
Huntley answered 27/3, 2018 at 20:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.