-
-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unexpected 'Fragment cannot be spread' error #493
Comments
Thanks, you are right. Query validation was written before we supported "interfaces", so i forgot to update it too. I will fix it |
@AlistairB i started it #495 |
@AlistairB please try it with actual master |
Unfortunately I am still getting the same error building with morpheus based on commit 57de511 (current head on master). |
ooh. that weird i wrote tests for it. can you share full schema? |
and query with fragment |
If you clone https://github.com/AlistairB/morpheus-repro and |
so, if we have schema. interface GitObject {
id: ID!
}
type Commit implements GitObject & Node {
id: ID!
author: String
}
type Query {
target: GitObject!
} your query would look like: {
target {
... on Commit {
author
}
}
} and would be invalid. as long so, if we had schema where target has concrete type interface GitObject {
id: ID!
}
type Commit implements GitObject & Node {
id: ID!
author: String
}
type Query {
target: Commit!
} then we could query on it {
t1: target {
... on Commit {
author
}
}
t2: target {
... on GitObject {
author
}
}
} |
Hmm, I'm not sure if I understand. My understanding is that you can use the spread operator to conditionally get data IF the type matches. For example using https://developer.github.com/v4/explorer/ query {
repository(owner: "facebook", name: "react") {
defaultBranchRef {
target {
id
... on Commit {
author {
name
}
}
}
}
}
} will fetch all this data, as On the other hand: query {
repository(owner: "facebook", name: "react") {
defaultBranchRef {
target {
id
... on Blob {
byteSize
}
}
}
}
} Will only fetch the id, but will not return an error. This is because And you can combine them: query {
repository(owner: "facebook", name: "react") {
defaultBranchRef {
target {
id
... on Commit {
author {
name
}
}
... on Blob {
byteSize
}
}
}
}
} In terms of the schema I am using, I have directly copied the bits I need from the official github public schema. See https://docs.github.com/en/graphql/overview/public-schema . This query with the schema does work on github which makes me think it is valid? |
@AlistairB okey. may i got something wrong. what you say looks like type casting. |
@AlistairB can you check again , i fixed it #498 |
@AlistairB validation workded well bot there is some problem with type Generation that i am fixing in #499 |
@AlistairB now it should finally work |
Thanks David! This is now working for most cases that I tested. The below is happy and works. query FetchRepoHeadCommit ($repoOwner: String!, $repoName: String!) {
repository(name: $repoName, owner: $repoOwner) {
defaultBranchRef {
target {
id
... on Commit {
committedDate
}
}
}
}
} However, I get an error if I remove returning the query FetchRepoHeadCommit ($repoOwner: String!, $repoName: String!) {
repository(name: $repoName, owner: $repoOwner) {
defaultBranchRef {
target {
... on Commit {
committedDate
}
}
}
}
} produces Possibly worth noting that I believe putting interface level fields inside the spread is also valid. eg. query FetchRepoHeadCommit ($repoOwner: String!, $repoName: String!) {
repository(name: $repoName, owner: $repoOwner) {
defaultBranchRef {
target {
... on Commit {
id
committedDate
}
}
}
}
} I think this is working aside from the above error. Although, I don't think supporting this style is super important. |
thanks @AlistairB. i fixed it in #500 |
Awesome, now working! thanks! |
Hi,
I am trying to use interfaces in my query using morpheus client. My gql file looks something like (excluded some excessive detail. Let me know if you want my full file):
And my query looks something like:
This fails with
Fragment cannot be spread here as objects of type \"GitObject\" can never be of type \"Commit\
. Changingtarget: GitObject!
totarget: Commit!
makes it work. This confuses me as I havetype Commit implements GitObject
.My expectation is that this should work based on
2
from https://github.com/morpheusgraphql/morpheus-graphql#interface . Am I missing something?The text was updated successfully, but these errors were encountered: