Filter nested array in graphQL - graphql

I am trying to filter an array of quotes based on what work or event the quote is referencing.
I only want the quotes referencing the current work the user is visiting. I've tried filtering, but I can't get it to work.
query MyQuery {
allSanityQuote {
edges {
node {
work {
... on SanityEvent {
_id
}
}
}
}
}
}
I want the _id in SanityEvent to match wphb0cG6N3lm4RQzm1xf51
Is SanityEvent a so called union? I've tried to read the graphQL documentation, but can't seem to find any example of this.

Related

How do I query a GitHub Project Item title from GraphQL?

I'm attempting to use the GitHub ProjectV2 API to query a GitHub Projects beta project to obtain the title or a given GitHub Project Item.
Unfortunately, I'm not well-versed in GraphQL and struggling to complete the query. What am I missing from the following GraphQL query to get this to work?
query {
node(id: \"PROJECT_NODE_ID\") {
... on ProjectV2 {
items(id:\"PROJECT_ITEM_ID\")
}
}
content{
... on DraftIssue {
title
}
}
}
As written, this returns the following error:
Field must have selections (field 'items' returns ProjectV2ItemConnection but has no selections. Did you mean 'items { ... }'?)"}
You're almost there, but there are two issues here:
items returns a Connection, which means you still need to include another set of curly braces to "select" which fields you'd like.
The GitHub ProjectsV2 API doesn't look like it supports selection of individual items yet, only paginating through a list of items. This means that what you actually want to use is something like:
query {
node(id: \"PROJECT_NODE_ID\") {
... on ProjectV2 {
items(first: 10) {
nodes {
content {
... on DraftIssue {
title
}
}
}
}
}
}
}

Graphql Filter by query

So I'm trying to learn graphql I've been playing around with the ENS subgraph on the graph
I've figured out how to do simple filtering but when I try to write more complex filters they do not compile.
I'm trying to get the top 5 transactions for the each of the top 5 domains. (e.g for each domain I want the top 5 transactions)
{
#Sample Query to get the first 5 domains (not needed for question but used to validate results)
domains(first: 5) {
id
name
labelName
labelhash
}
#attempt to filter the transfer.domain.id by TOP 5 domains.id
transfers(where: { domain { id: domains(first: 5) { id } } }) {
id
domain {
id
}
blockNumber
transactionID
}
}
EDIT I'm going to attempt to simplify my request since I'm not sure nesting queries is possible. How can I filter an inner query by Id:
transfers(where: {domain.id: "0x9c0fc2519ae862cee27778e5c34714d6c7e3ca21ad572df47ad9f6fe530909bd"}) {
id
domain {
id
}
blockNumber
transactionID
}
NOTE: Domain.Id = does not compile how would I write a filtered query like that?
However, My filter doesn't compile syntactically. How can I write a query which filters by a child property?
You can query like this
query {
getPost(id: "0x1") {
title
text
datePublished
}
}
Got this from https://dgraph.io/docs/graphql/queries/search-filtering/

insert items into array using graphql - Parse server

I have a class that contains a field called 'notes'. Its data type is array. In the mutation, I'm able to save data on the field. problem is it overwrites the value. I want to add value in the array. how do I do it? here's my mutation. I know I'm not doing the right thing, but can't find it in the documentation as well
mutation {
updateParcel(input: { id: "B6aESEwWcA", fields: { notes: ["wow"]}}) {
parcel {
objectId
notes {
... on Element {
value
}
}
}
}
}

How do you perform operations on variables in GraphQL?

I am a traditional programmer new to GraphQL and I can't seem to find documentation on what I consider the basics, aka manipulating variables. Note: I am using GraphQL with Shopify(Admin API), through an app GraphiQL, so that my effect syntax and capabilities.
Here is a piece of hypo (& broken) code where I have two iterations of the same code block
<>that tries to add two variables
<>on that sum items in a list. The specific code in this lines are guesswork..
If anyone has suggestions on sources for example code or API docs beyond GraphQL site, I have been searching and nothing I have found addresses this type of functionality.
query fiveorTenOrders($n: Int = 5,$m: list =[5,5], $boo: Boolean = true) {
FiveOrds: orders(first: $n) {
edges #include(if: $boo) {
node {
...ordrecs
}
}
}
#<<<HERE and as basic arithmetic>>>
TenOrds: orders(first: ($n+$n) {
edges #skip(if: $boo) {
node {
...ordrecs
#<<<OR HERE ...as a sum of list>>>
TenOrds: orders(first: $m:SUM {
edges #skip(if: $boo) {
node {
...ordrecs
}
}
}
}
fragment ordrecs on Order {
id
name
createdAt
shippingAddress {
id
city
provinceCode
zip
}
}
GraphQL does not currently support this sort of functionality (and may never). Variables are used as-is with no way to apply arbitrary transformations to them. In your example, you would need to sum the values yourself on the client and then inject them into the query as a separate variable.

How can I do a WpGraphQL query with a where clause?

This works fine
query QryTopics {
topics {
nodes {
name
topicId
count
}
}
}
But I want a filtered result. I'm new to graphql but I see a param on this collection called 'where', after 'first', 'last', 'after' etc... How can I use that? Its type is 'RootTopicsTermArgs' which is likely something autogenerated from my schema. It has fields, one of which is 'childless' of Boolean. What I'm trying to do, is return only topics (a custom taxonomy in Wordpress) which have posts tagged with them. Basically it prevents me from doing this on the client.
data.data.topics.nodes.filter(n => n.count !== null)
Can anyone direct me to a good example of using where args with a collection? I have tried every permutation of syntax I could think of. Inlcuding
topics(where:childless:true)
topics(where: childless: 'true')
topics(where: new RootTopicsTermArgs())
etc...
Obviously those are all wrong.
If a custom taxonomy, such as Topics, is registered to "show_in_graphql" and is part of your Schema you can query using arguments like so:
query Topics {
topics(where: {childless: true}) {
edges {
node {
id
name
}
}
}
}
Additionally, you could use a static query combined with variables, like so:
query Topics($where:RootTopicsTermArgs!) {
topics(where:$where) {
edges {
node {
id
name
}
}
}
}
$variables = {
"where": {
"childless": true
}
};
One thing I would recommend is using a GraphiQL IDE, such as https://github.com/skevy/graphiql-app, which will help with validating your queries by providing hints as you type, and visual indicators of invalid queries.
You can see an example of using arguments to query terms here: https://playground.wpgraphql.com/#/connections-and-arguments

Resources