简体   繁体   English

错误:只能有一个名为“ fragmentName”的片段

[英]Error: There can be only one fragment named “fragmentName”

I am changing the format of my schema from this: 我正在从此更改架构的格式:

var OldSchema = new GraphQLSchema({
  query: queryType,
  mutation: mutationType
});

to this: 对此:

typeDef = `
type Query {
  posts: [Post]
  author: Author
}
`;

const NewSchema = makeExecutableSchema({
  typeDefs: [typeDef],
  resolvers: resolvers
});

Since I have a lot of fields, and I want to transfer them from the old format to the new format one by one, I am using the function mergeSchemas from graphql-tools: 由于我有很多字段,并且想将它们从旧格式一一转换为新格式,因此我使用了来自graphql-tools的功能mergeSchemas

export const RootSchema = mergeSchemas({
  schemas: [NewSchema, OldSchema]
});

When I try to create a query ( which only get fields from the OldSchema ), I get the error **There can be only one fragment named "duty". 当我尝试创建查询(仅从OldSchema获取字段)时,出现错误**只能有一个名为“ duty”的片段。

This is how my query looks: 这是我的查询的样子:

query {
  person {
    ...personFragment
  }
}
fragment conceptFragment on Person {
  jobs {
    ... on techJob {
      ...activities
    }
    ... on carpentryJob {
      ...skillSet
    }
  }
}
fragment activities on techJob {
  duties {
    ...duty
  }
}
fragment duty on Duties {
  id
}
fragment skillSet on carpentryJob {
  skills {
    ...dutiesSkill
  }
}
fragment dutiesSkill on Skill {
  duties {
    ...duty
  }
}

I know the error is happening in the parsing and it seems that the Validation of the query is happening for the OldSchema and for the RootSchema, but the RootSchema is the one that fails. 我知道该错误正在分析中发生,并且似乎为OldSchema和RootSchema进行了查询验证,但是RootSchema失败了。

You can maybe give an alias to one of the fragments? 您也许可以给其中一个片段起alias Like: 喜欢:

fragment activities on techJob {
  activities: duties {
    ...duty
  }
}

And

fragment dutiesSkill on Skill {
  dutiesSkill: duties {
    ...duty
  }
}

This issue has been resolved by updating to the v14.0.0-rc.2 release. 通过更新到v14.0.0-rc.2版本已解决了此问题。 There is no mention about the issue being resolved. 没有提及要解决的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM