How do u make multiple request inside one graphql request with Appwrite and NextJS, there is my code :
const q = (await graphql.query([
{
query: `query {
databasesListDocuments(
databaseId: "${String(process.env.NEXT_PUBLIC_APPWRITE_DATABASE_USERS)}",
collectionId: "${String(process.env.NEXT_PUBLIC_APPWRITE_COLLECTION_MOVIE_LIKED)}",
queries: ["equal('userId', ${userId})", "equal('movieId', ${movieId})"]
) {
total
documents {
_id
_collectionId
_databaseId
_createdAt
_updatedAt
_permissions
data
}
}
}`
}
]))
Here I only take the likes from a specific user and specific movie. Now I also want to get the "asSeen" state from another collection, how can I do ?
I saw some exmaple like this :
query getAuthors {
authors {
firstName
lastName
}
}
// Query to get all posts
query getPosts {
posts {
id
title
exert
}
}
But how add custom name from each call ? like "getAuthors", "getPosts"
I dont understand the utility of "operationName" if I can call multiple operationName :/
from "Appwrite GraphQL Overview" (youtube video) I also dont understand how he got custom name like this
what do you mean? you can put whatever you like
these are not custom names. these are method calls
here's an example: https://appwrite.io/docs/graphql#query-batching
well there is something I dont understand ahah, how can I do multiple listDocument (for getting likes and "asSeen" state for example) :
const q = await graphql.query(
{
query: `
query GetAction {
databasesListDocuments(
databaseId: "${String(process.env.NEXT_PUBLIC_APPWRITE_DATABASE_USERS)}",
collectionId: "${String(process.env.NEXT_PUBLIC_APPWRITE_COLLECTION_MOVIE_LIKED)}",
queries: ["equal('userId', ${userId})", "equal('movieId', ${movieId})"]
) {
total
documents {
_id
_collectionId
_databaseId
_createdAt
_updatedAt
_permissions
data
}
}
databasesListDocuments(
databaseId: "${String(process.env.NEXT_PUBLIC_APPWRITE_DATABASE_USERS)}",
collectionId: "${String(process.env.NEXT_PUBLIC_APPWRITE_COLLECTION_MOVIE_WATCHED)}",
queries: ["equal('userId', ${userId})", "equal('movieId', ${movieId})"]
) {
total
documents {
_id
_collectionId
_databaseId
_createdAt
_updatedAt
_permissions
data
}
}
}
`,
}
)
console.log('graphql', q)
because in my code ive got this error :
"Fields "databasesListDocuments" conflict because they have differing arguments. Use different aliases on the fields to fetch both if this was intentional."
maybe this will help: https://atheros.ai/blog/how-to-use-graphql-aliases
Ive got this error because I use two time databasesListDocuments
but ive no other choice :/
did you look at what i linked?
Query batching ? yes but in the example they use method call "accountGet" and "localeGet" but no databaseslistdocuments
I guess there is something I dont understand
i meant this...
yeah they add custom name for each call like this :
likes: databasesListDocuments(
databaseId: "${String(process.env.NEXT_PUBLIC_APPWRITE_DATABASE_USERS)}",
collectionId: "${String(process.env.NEXT_PUBLIC_APPWRITE_COLLECTION_MOVIE_LIKED)}",
queries: ["equal('userId', ${userId})", "equal('movieId', ${movieId})"]
) {
total
documents {
_id
_collectionId
_databaseId
_createdAt
_updatedAt
_permissions
data
}
}
watch: databasesListDocuments(
databaseId: "${String(process.env.NEXT_PUBLIC_APPWRITE_DATABASE_USERS)}",
collectionId: "${String(process.env.NEXT_PUBLIC_APPWRITE_COLLECTION_MOVIE_WATCHED)}",
queries: ["equal('userId', ${userId})", "equal('movieId', ${movieId})"]
) {
total
documents {
_id
_collectionId
_databaseId
_createdAt
_updatedAt
_permissions
data
}
}
but when i do that im getting Max query complexity should be 250 but got 450
😢
The only way to dont have this error is delete some output result (like _collectionId
, _createdAt
, etc...)
Well I guess its okay I dont need all these data
But why there is a limit ? ive weed need a lot of result how can we do it ?
you can also modify the complexity: https://appwrite.io/docs/environment-variables#graphql
ohhh mb ahah
[SOLVED] Starting with GraphQL
Recommended threads
- Query Appwrite
Hello, I have a question regarding Queries in Appwrite. If I have a string "YYYY-MM", how can I query the $createdAt column to match this filter?
- Different appwrite IDs are getting expos...
File_URL_FORMAT= https://cloud.appwrite.io/v1/storage/buckets/[BUCKET_ID]/files/[FILE_ID]/preview?project=[PROJECT_ID] I'm trying to access files in my web app...
- Invalid document structure: missing requ...
I just pick up my code that's working a week ago, and now I got this error: ``` code: 400, type: 'document_invalid_structure', response: { message: 'Inv...