GraphQL解析器返回已知字段的未知字段错误

时间:2019-03-01 14:59:38

标签: reactjs graphql relayjs

我正在从同一项目的有效实现中构建新的createRefetchContainer(),但是在运行yarn relay时遇到此错误:

ERROR:
GraphQLParser: Unknown field `usersByName` on type `Viewer`. 
Source: document `AutocompleteUsersContainer_UsersRefetchQuery` file:
 `client/components/Autocomplete/Users/AutocompleteUsersContainer.js`.

错误的继电器功能:

export default createRefetchContainer(
  AutocompleteUsers,
  graphql`
    fragment AutocompleteUsersContainer_viewer on Viewer
      @argumentDefinitions(name: { type: "String", defaultValue: "" }) {
      usersByName(name: $name)
    }
  `,
  graphql`
    query AutocompleteUsersContainer_UsersRefetchQuery(
      $name: String!
    ) {
      viewer {
        usersByName(name: $name){
          id
        }
      }
    }
  `
);

有效的实现方式

export default createRefetchContainer(
  AutocompleteLocations,
  graphql`
    fragment AutocompleteLocationsContainer_viewer on Viewer
      @argumentDefinitions(searchValue: { type: "String", defaultValue: "" }) {
      locations(searchValue: $searchValue)
    }
  `,
  graphql`
    query AutocompleteLocationsContainer_LocationsRefetchQuery(
      $searchValue: String!
    ) {
      viewer {
        locations(searchValue: $searchValue)
      }
    }
  `
);

下面的usersByName查询直接在graphql中返回结果,这就是为什么我不确定relay为什么说Unknown field 'usersByname'的原因:

query getViewer{
  viewer {
    usersByName(
      name: "Test Name"
    ) {
      id
    }
  }
}

1 个答案:

答案 0 :(得分:1)

通过在val path = File(".").toAbsolute //D:\app\idea2016\bin\ System.getProperty("user.dir") //D:\app\idea2016\bin\ 之前运行yarn schema来解决