Skip to content

Instantly share code, notes, and snippets.

@matthiasg
Last active December 13, 2016 07:30
Show Gist options
  • Save matthiasg/c05696fd525768c735b57bdeca67c29e to your computer and use it in GitHub Desktop.
Save matthiasg/c05696fd525768c735b57bdeca67c29e to your computer and use it in GitHub Desktop.
Example of GraphQl issues with respect to filtering. Duplicated filter on data__noxe reference field. Also potentially conflicting with different versions.

Given a schema with three entities cases,products,noxe where cases and products link to noxe via field data__noxe and where the type noxe is a union of two major versions Noxe_v1 and Noxe_v2.

If the noxe should be filtered (by parent AND other properties) then the code to filter might be duplicated if put into the resolvers naively. The code can be easily be factored out but the duplication in the arguments remains AND is complicated by the fact that different filters might be needed for different versions of Noxe.

Looking at the line 4: data__noxe(match:"some n2") { we can see an argument data__value which is supposed to define a filter on field data__value. When adding another filter only present in one of the versions data__noxe(data__value:"eq:some n2" data__sometext:"contains:some") {

It would be nicer if the potential input arguments could be directly applied to the fields to avoid duplication on the server side and opt-in on the client side. See https://gist.github.com/matthiasg/c05696fd525768c735b57bdeca67c29e#file-4-field-level-filtering-mix

{
cases {
id
data__noxe(data__value:"eq:some n2") {
__typename
... on Noxe_v1 {
id
data__value
data__sometext
}
... on Noxe_v2 {
id
data__value
data__somenumber
}
}
}
}
{
products {
id
data__noxe(data__value:"eq:some n2") {
__typename
... on Noxe_v1 {
id
data__value
data__sometext
}
... on Noxe_v2 {
id
data__value
data__somenumber
}
}
}
}
products {
id
data__noxe() {
__typename
... on Noxe_v1 {
id
data__value(eq:"some n2")
data__sometext(contains:"some")
}
... on Noxe_v2 {
id
data__value(eq:"some n2")
data__somenumber(gt:2)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment