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
Invalid error being returned: Fields "first" conflict because they have differing arguments. #943
Comments
Thanks for reporting this issue, I need to check out the GraphQL spec. 😁 |
It looks like this is not allowed in the GraphQL spec. |
Please correct me if I'm wrong, but I think that's just saying you can't merge the fields in this case. I.e., they need to be handled separately, as you would aliased fields. I believe this is what https://github.com/99designs/gqlgen does, which handled the query at the top of this report without issues. I'll see if I can dig into the code and see how they're handling this case. |
Please let me know if there is any progress. 😄 |
I looked into this a little today. The issue is subtle because fragments are involved, and I didn't find much discussion in the spec around fragments. But in this case the union SearchResultItem = Topic | Link
type SearchResultItemEdge {
node: SearchResultItem!
}
type SearchResultItemConnection {
edges: [SearchResultItemEdge]
}
type Topic {
search(
searchString: String!,
first: Int,
after: String,
last: Int,
before: String
): SearchResultItemConnection!
} Here is the relevant part of the query above: search(searchString: $searchString) {
edges {
node {
__typename
... on Topic {
id
...Topic_topic
}
... on Link {
id
...Link_link
}
}
}
} In cases where there is a union, the field has the same name, the arguments differ, and the parent field types, which are members of the union, differ, it seems this is allowed and that the field is not merged across the different types in the union: So the validation and field collection code probably need to take into account the type that is including the field with the differing arguments. I looked into the |
Thanks a lot, I'll dig into it later. 🙂 |
I fixed this on the |
@sunli829 I will try to test this soon. For the moment, I'm seeing this error when I switch to This is the code where this happens: #[post("/graphql")]
async fn index(
state: web::Data<State>,
gql_request: GraphQLRequest,
req: HttpRequest,
) -> GraphQLResponse {
let user_info = user_id_from_header(req);
let viewer = state.authenticate(user_info).await;
let repo = state.create_repo(viewer);
let request = gql_request.into_inner().data(repo);
state.schema.execute(request).await.into()
} |
You need to update these two dependencies: async-graphql = { git = "https://github.com/async-graphql/async-graphql", branch = "master" }
async-graphql-actix-web = { git = "https://github.com/async-graphql/async-graphql", branch = "master" } |
That got things working. After switching to |
Released in |
First off, thank you for the excellent library. I'm enjoying using it.
Expected Behavior
Query fragments are intended to be used by (e.g., React/Relay) components without needing to coordinate their fragment queries globally across the app and across the consolidated query that is constructed by combining the fragments. This allows components to be developed in isolation without having side effects for other components referring to the same fields. My understanding is that a fragment should provide a namespace of sorts in cases where the same field is being requested across different fragments with different values for the arguments and should work similarly to aliasing the common field with different aliases.
Actual Behavior
When two fragments referring to the same field use different values of the
first:
argument for a Relay connection, the following error is reported:Here is the query that triggers this error:
Fragment query
In this case,
parentTopics(first: 1000)
conflicts withparentTopics(first: 100)
, even though the shared field is referred to in different fragments. A workaround is to adjust the argument value to be the same (e.g, 100). This means the different components have to know about one another and coordinate their behavior. But the components could be from different teams or even different libraries, so that kind of low-level coordination shouldn't be needed.I believe this is the code doing the validation. Some kind of fragment-related namespacing might be needed to avoid the validation error.
Specifications
async-graphql
3.0.38The text was updated successfully, but these errors were encountered: