Describe the bug
in single schema a second query and mutation section is ignored by schema compiler.
To Reproduce
type A@model(queries: null, mutations: null) { id: ID!, name: String }
type B@model(queries: null, mutations: null) { id: ID!, name: String }
type Mutation {
createA(id: ID!): A
}
type Query {
getA(id: ID!): A
}
type Mutation {
createB(id: ID!): B
}
===
Expected behavior
Since this isn't valid the compiler should throw an error, instead it just ignores the extra entries. It would be better if it merged them, but I think the correct behavior is to throw an error so the programmer can correct the file.
Thank You.
@ryanhollander Thanks for the comment. I tend to agree that compilation should fail if you try to define two types with the same name (e.g. how you define two types named Mutation). You can get the behavior you want by using the extend keywork for the second Mutation type.
type Mutation {
createA: String
}
extend type Mutation {
createB: String
}
I have made a note of this and we will include adding the extra validation to the backlog.
Sounds good thanks @mikeparisstuff !
There maybe an implementation detail still not being clarified, it looks like the type Mutation in alphabetically ordered first file should have type Mutation and other should have extend type Mutation for it to work.
OK
schema/a.graphql
type A {
id: ID!
}
type Mutation {
createA: A
}
schema/b.graphql
type B {
id: ID!
}
extend type Mutation {
createB: B
}
FAILED
schema/a.graphql
type A {
id: ID!
}
extend type Mutation {
createA: A
}
schema/b.graphql
type B {
id: ID!
}
type Mutation {
createB: B
}
Failed with
脳 An error occurred when pushing the resources to the cloud
Type kind "ObjectTypeExtension" not supported.
Update:
And for case of "extend type Mutation createA" + "extend type Mutation createB" the error message is different from previous failed case.
Cannot extend non-existant type 'Mutation'.
For those arriving at this page, please take a look at the linked #2596 before you attempt to use extend type Mutation -- you _will not_ get generated cloud formation templates and resolvers from your extended, additional Mutations/Queries.
Most helpful comment
There maybe an implementation detail still not being clarified, it looks like the
type Mutationin alphabetically ordered first file should havetype Mutationand other should haveextend type Mutationfor it to work.OK
schema/a.graphql
schema/b.graphql
FAILED
schema/a.graphql
schema/b.graphql
Failed with
Update:
And for case of "extend type Mutation createA" + "extend type Mutation createB" the error message is different from previous failed case.