【问题标题】:Implement multiple interfaces in graphql在graphql中实现多个接口
【发布时间】:2018-09-06 09:00:40
【问题描述】:

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

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

如果你用 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"

任何想法为什么会发生这种情况?

【问题讨论】:

    标签: reactjs graphql relay relaymodern


    【解决方案1】:

    对于多个接口,您应该使用与号而不是逗号。 见这里:http://facebook.github.io/graphql/draft/#sec-Interfaces

    type Something implements First & Second
    

    【讨论】:

      猜你喜欢
      • 2017-12-26
      • 2022-08-02
      • 1970-01-01
      • 1970-01-01
      • 2018-06-26
      • 1970-01-01
      • 1970-01-01
      • 2020-01-13
      • 2015-10-09
      相关资源
      最近更新 更多