Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Implement multiple interfaces in 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

{
  "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?

like image 964
Piotr Avatar asked Jan 02 '23 14:01

Piotr


1 Answers

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
like image 179
celticpride Avatar answered Jan 05 '23 16:01

celticpride