0

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:

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".

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.

Adolfo
  • 1,315
  • 2
  • 14
  • 22
  • is it that ...duty should be duty? – Joe Warner Jul 12 '18 at 12:22
  • No, that is refering to the fragment fragment duty on Duties. The issue is that the validation is happening for the OldSchema and the RootSchema. But whenever it does the validation for the OldSchema it messes up and it treats all the ... as fragment definitions, instead of inline fragments. – Adolfo Jul 12 '18 at 16:50
  • Things might be more clear using UpperCase for type names and fragment names so that you don't confuse them with fields. – brysgo Jul 12 '18 at 18:17
  • I would be interested in seeing what the query looks like after it has been rewritten by the schema merging to get the data from "OldSchema". – brysgo Jul 12 '18 at 18:23

2 Answers2

0

You can maybe give an alias to one of the fragments? Like:

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

And

fragment dutiesSkill on Skill {
  dutiesSkill: duties {
    ...duty
  }
}
Marco Daniel
  • 5,467
  • 5
  • 28
  • 36
0

This issue has been resolved by updating to the v14.0.0-rc.2 release. There is no mention about the issue being resolved.

Adolfo
  • 1,315
  • 2
  • 14
  • 22