be4r
08/29/2017, 9:02 PMRed
, Green
, Blue
. Sometimes they just want Red
, sometimes they might want anything that is Red
Or Blue
, or sometimes they might just want it all. How can I write this query so it is dynamic based on what I pass from the client? Because writing a query like this wouldn’t be too dynamic.
{
allPokemons(filter:{
OR: [
{
colorses_some: {
color:"Green"
}
},
{
colorses_some: {
color:"Red"
}
}
]
}){
name
}
}
agartha
08/29/2017, 9:07 PMquery($colors: [String!]!){
allPokemons(filter: { colorses_some: { color_in: $colors}})
{
id
}
}
with variables:
{
"colors": [
"RED",
"BLUE"
]
}
be4r
08/29/2017, 9:08 PMagartha
08/29/2017, 9:08 PMcolorses_some
to colorses_every
, otherwise I think you will always get all Pokemonsbe4r
08/29/2017, 9:09 PMred
OR blue
correct?be4r
08/29/2017, 9:09 PMcolorses_every
returns result that is red
AND blue
agartha
08/29/2017, 9:10 PMbe4r
08/29/2017, 9:10 PMagartha
08/29/2017, 9:10 PMbe4r
08/29/2017, 9:10 PMcolorses_every
i get 1 result that has both colorsagartha
08/29/2017, 9:10 PMagartha
08/29/2017, 9:11 PMcolorses_some
works?be4r
08/29/2017, 9:11 PMbe4r
08/29/2017, 9:11 PMbe4r
08/29/2017, 9:11 PMagartha
08/29/2017, 9:12 PMagartha
08/29/2017, 9:13 PMbe4r
08/29/2017, 9:16 PMbe4r
08/30/2017, 4:16 PMcolors_every
. We created a Colors
schema to categorize cards by color and with colors_some
it seems to be working fine by returning blue/black/blueblack.
query{
allCards(filter:{
colors_some: {
id_in: ["cj6yfq72z7uos0167kty5jab7", "cj6yfq1mdu66g01241w4nib9n"]
}
})
{
colors {
color
}
name
}
}
be4r
08/30/2017, 4:17 PMcolors_every
we do get blues/blacks/blueblacks but also ones that should not return like below:be4r
08/30/2017, 4:18 PM{
"colors": [
{
"color": "Black"
}
],
"name": "Yahenni, Undying Partisan"
},
{
"colors": [
{
"color": "Black"
}
],
"name": "Renegade's Getaway"
},
{
"colors": [
{
"color": "Blue"
},
{
"color": "Black"
}
],
"name": "Tezzeret the Schemer"
},
{
"colors": [
{
"color": "Blue"
},
{
"color": "Black"
}
],
"name": "Tezzeret's Touch"
},
{
"colors": [],
"name": "Aegis Automaton"
},
{
"colors": [],
"name": "Crackdown Construct"
},
{
"colors": [],
"name": "Filigree Crawler"
},
{
"colors": [],
"name": "Implement of Combustion"
},
{
"colors": [],
"name": "Implement of Examination"
},
{
"colors": [],
"name": "Implement of Ferocity"
},
{
"colors": [],
"name": "Implement of Improvement"
},
{
"colors": [],
"name": "Implement of Malice"
},
{
"colors": [],
"name": "Metallic Mimic"
},
{
"colors": [],
"name": "Merchant's Dockhand"
},
{
"colors": [],
"name": "Inspiring Statuary"
},
{
"colors": [],
"name": "Lifecrafter's Bestiary"
},
{
"colors": [],
"name": "Irontread Crusher"
},
{
"colors": [],
"name": "Paradox Engine"
},
{
"colors": [],
"name": "Mobile Garrison"
},
{
"colors": [],
"name": "Peacewalker Colossus"
},
{
"colors": [],
"name": "Ornithopter"
},
{
"colors": [],
"name": "Pacification Array"
},
{
"colors": [],
"name": "Night Market Guard"
},
{
"colors": [],
"name": "Renegade Map"
},
{
"colors": [],
"name": "Planar Bridge"
},
{
"colors": [],
"name": "Prizefighter Construct"
},
{
"colors": [],
"name": "Scrap Trawler"
},
{
"colors": [],
"name": "Reservoir Walker"
},
{
"colors": [],
"name": "Universal Solvent"
},
{
"colors": [],
"name": "Watchful Automaton"
},
{
"colors": [],
"name": "Treasure Keeper"
},
{
"colors": [],
"name": "Untethered Express"
},
{
"colors": [],
"name": "Verdant Automaton"
},
{
"colors": [],
"name": "Spire of Industry"
},
{
"colors": [],
"name": "Walking Ballista"
},
{
"colors": [],
"name": "Welder Automaton"
},
{
"colors": [],
"name": "Tranquil Expanse"
},
{
"colors": [
{
"color": "Blue"
},
{
"color": "Black"
}
],
"name": "Tezzeret, Master of Metal"
},
{
"colors": [
{
"color": "Blue"
},
{
"color": "Black"
}
],
"name": "Tezzeret's Betrayal"
},
{
"colors": [],
"name": "Tezzeret's Simulacrum"
},
{
"colors": [],
"name": "Pendulum of Patterns"
},
{
"colors": [],
"name": "Submerged Boneyard"
}
]
be4r
08/30/2017, 4:18 PMagartha
08/30/2017, 4:19 PMcolors_every
apparently returns true
is colors == []
agartha
08/30/2017, 4:25 PMagartha
08/30/2017, 4:28 PMcolors_some
also includes results where one of the colors is NOT in your list (so, colors_some: ["RED", "BLUE"]
also includes results that are RED and YELLOWagartha
08/30/2017, 4:29 PMcolors_every
makes sure that every color is in that list, so it should only return RED only, BLUE only, or RED and BLUE only, without other colorsagartha
08/30/2017, 4:41 PMbe4r
08/30/2017, 5:40 PMbe4r
08/30/2017, 5:41 PMcolors_every
.be4r
08/30/2017, 6:00 PMjt9001
08/30/2017, 9:01 PMagartha
08/30/2017, 9:10 PM_some
, except for the 'only one of these colors' query. Also, you only run into this problem when you have parents with an empty child collection. If every card has 1+ colors, the _every
query works fine...agartha
08/30/2017, 9:11 PM_every
bug.jt9001
08/30/2017, 9:13 PMagartha
08/30/2017, 9:28 PMcolors_every: { color_in: ["blue", "black"] }
will NOT exclude cards with other colors. If you know all colors on the client, you could do: AND: [ { colors_every: { color_in: ["blue", "black"] } }, { colors_every: { color_not_in: [ "all", "other", "colors" ] } } ]
to ONLY show cards with either blue OR black. Making it even more difficult, if you ONLY want cards with blue AND black, you need to split it like in the original filter above, with AND: [ { colors_some: { color: "blue } }, { colors_some: { color: "black" } }, { colors_every: { color_not_in: [ "all", "other", "colors" ] } } ]
agartha
08/30/2017, 9:28 PMbe4r
08/31/2017, 1:09 AM['None']
(None being an id that links to a Color with color: 'None'
and the filtering works as expected. Thank you so much for your help!