GraphQL Seach Items By Attribute - graphql

I'm new to graphql and I'm looking to build a query for an existing API (link). This Schema has the entity ClaimedToken that has a field called lending which is of type GotchiLending (another object). What I am trying to do, is simply to list all ClaimedTokens based on the borrower of GotchiLending (claimedToken.lending.borrower === "0x081b0ebac365be1d64febdcc66bdb4f14c37813b").
Here is what I have tried:
Put borrower on lending field
{
claimedTokens {
lending(borrower: "0x081b0ebac365be1d64febdcc66bdb4f14c37813b") {
borrower
}
}
}
Put borrower on claimedTokens
{
claimedTokens(borrower: "0x081b0ebac365be1d64febdcc66bdb4f14c37813b") {
lending {
borrower
}
}
}
Using where
{
claimedTokens {
lending(where: { borrower: "0x081b0ebac365be1d64febdcc66bdb4f14c37813b" }) {
borrower
}
}
}
Using find
{
claimedTokens {
lending(find: { borrower: "0x081b0ebac365be1d64febdcc66bdb4f14c37813b" }) {
borrower
}
}
}
Surprisingly, all my queries were ignored and no errors or warnings were raised. Again, I'm a beginner in graphql so I might be missing something obvious.
Thanks in advance,
Ernani

Related

GraphQL query filtering multiple relations

(From Strapi) I am trying to get all "acts" with a certain age (can return multiple) and with a certain place (can return multiple). I can't figure out how to filter that.
This is what I am trying in GraphQL-playground (works without the variables), but it says "Unknown argument "age" on field "Act.ages"." (and "place" respectively).
query GetActs ($age:Int, $place:String) {
acts {
data {
id
attributes {
Title
ages (age: $age) {
data {
id
attributes {
age
}
}
}
places (place: $place) {
data {
id
attributes {
place
}
}
}
}
}
}
}
I just ran into this same issue. I can't make out the error you're reporting, but here is what worked for me.
You can use filter at the collection level to drill down to nested fields for the corresponding attributes. This follows the GraphQL example at the bottom of this Strapi resource on filtering nested fields.
Solution
query GetActs ($age:Int, $place:String) {
acts (filters: {ages: {age: {eq: $age}}, places: {place: {eq: $place}}}) {
data {
id
attributes {
Title
ages {
data {
id
attributes {
age
}
}
}
places {
data {
id
attributes {
place
}
}
}
}
}
}
}

Shopify Admin API, graphQL, create draft order - add products

This is my fist time creating an order. From what I understand you need to create a draft order - add products, price, email, notes etc. I am just creating a test query now to see how it works and it tells me "Add at least 1 product". I am trying to add a product, but I dont know how. I have been messing around and reading and cant figure it out.
This is my query:
mutation draftOrderCreate {
draftOrderCreate(input: {email: "123abc#hotmail.com"}) {
draftOrder {
id
order {
id
}
status
}
userErrors {
field
message
}
}
}
If anyone can give me an example on how to add products to this would be great. Thanks.
You can create an draft order like so:
mutation draftOrderCreate($items: DraftOrderInput!) {
draftOrderCreate(input: $items) {
draftOrder {
id
order {
id
}
status
}
userErrors {
field
message
}
}
}
query variables:
{
"items": {
"email": "123abc#hotmail.com",
"lineItems": [
{
"variantId": "gid://shopify/ProductVariant/32231002996788",
"quantity": 1
}
]
}
}
Or if you don't want to use query variables you can pass the whole object as the input:
mutation draftOrderCreate {
draftOrderCreate(input: {email: "123abc#hotmail.com", lineItems: [{variantId: "gid://shopify/ProductVariant/32231002996788", quantity: 1}]}) {
draftOrder {
id
order {
id
}
status
}
userErrors {
field
message
}
}
}

Is it possible to filter a collection based on a collection field on the content type in graphql & contentful

This might be impossible in graphql/contentful or introduce too much complexity but I'm trying to query a collection and filter on a collection field, something like the following...
query {
eventCollection(
where: {
OR: [
{ categoryCollection: { key: "fashion" } }
]
}
) {
items {
slug
}
}
My back up plan is to query all the events and filter in the client but I thought it would be possible to do the above.
Contentful DevRel here. 👋
Currently, that's not possible. But what you can do is flip the query around and filter on the categoryCollection and then use linkedFrom to request the items linking to it.
query {
categoryCollection(where: {
key: "fashion
}) {
items {
title
linkedFrom {
eventCollection {
items {
slug
}
}
}
}
}
}

Update Local State when Creating and Deleting Associations in Apollo Client

I have objects of type student and team in my schema and a table student_team that keeps records of their relationships.
To manage these I use the following calls:
// to add a student team relationship
mutation CreateStudentTeam($studentId: UUID!, $teamId: UUID!) {
createStudentTeam(
input: { studentTeam: { studentId: $studentId, teamId: $teamId } }
) {
student {
id
}
team {
id
}
}
}
// to remove a student team relationship
mutation DeleteStudentTeam($studentId: UUID!, $teamId: UUID!) {
deleteStudentTeamByStudentIdAndTeamId(input: {studentId:$studentId, teamId:$teamId}) {
student {
id
}
team {
id
}
}
}
// to view teams with students
query Teams {
teams {
nodes {
id
name
students {
nodes {
id
fullName
}
}
}
}
}
My application presents data based on these relationships as listings.
A team might be presented with a listing of students.
I'm a bit confused about how to update the local state after making these calls.
Would the best thing to do to just redo the fetch for the data with the Teams query?
I'd love to know how best to do it with the Apollo Link State.
Thanks!
You need to do it manually using update prop passed:
graphql(YourMutation, {
options: {
update: (cache, result) => {
const query = TeamsQuery
const currentQueryData = cache.readQuery({query})
const updatedData = //change your data regarding of the mutation
cache.writeQuery({query, data: graphql updatedData })
}
}
}
also have a look at this part of the docs

How to get variant by variant Id from product object using by graphql Shopify

Query so far
{
product1: product(id: "gid://shopify/Product/777854222396") {
title
totalVariants
variants(first:99) {
.....
}
hasOutOfStockVariants
}
product2: product(id: "gid://shopify/Product/511571296316") {
title
}
}
What can be done to fetch variant based on id
I have found ProductVariant on their GraphQL Admin API reference docs, you can take reference from their else I didn't find any ProductVariant Schema open at QueryRoot as defined here in the open graphQL admin panel although they have mentioned an example.
query {
productVariant(id: "gid://shopify/ProductVariant/10782354800682") {
inventoryItem {
inventoryLevels (first:10) {
edges {
node {
location {
name
}
available
}
}
}
}
}
}

Resources