Yeah I thought the same thing at the beginning
Apollo Client and Appwrite
Votes
0
Replies
24
Participants
Unknown
Messages
25
Rank 3: Container
Apollo Client got a functionnality called "batching" that allow to make multiple query into one but quite complicated to setup with appwrite
Rank 3: Container
Okay im trying to make graphql request with Apollo Client but im not able to pass variable inside :
const GET_LIKE_STATE = gql`
query GetLikeState($userId: String!, $movieId: String!) {
like: 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)"]
) {
documents {
_id
}
}
}
`;
const { loading: isLoading, error: isError, data: isLiked } = useQuery(GET_LIKE_STATE, {
variables: {
userId: "64abdd24ace0ed78ab19",
movieId: "545611",
}
})
Im getting this error :
{
"errors": [
{
"message": "Variable \"$userId\" is never used in operation \"GetLikeState\".",
"extensions": {
"category": "graphql"
},
"locations": [
{
"line": 1,
"column": 20
}
]
},
{
"message": "Variable \"$movieId\" is never used in operation \"GetLikeState\".",
"extensions": {
"category": "graphql"
},
"locations": [
{
"line": 1,
"column": 38
}
]
}
]
}
Rank 3: Container
that's so weird, im not able to pass variable inside the query
Rank 3: Container
Ive try this :
Rank 3: Container
but i have a inifnite pending state on my request
Can you show us the request from the network tab?
Rank 3: Container
are you using self hosted right?
If so, can you check the output from docker compose logs appwrite
Rank 3: Container
in the log of appwrite container (from Docker Desktop) :
Rank 3: Container
in this exemple $userId = 64abdd24ace0ed78ab19
Rank 3: Container
so I guess the problem is inside the queries but idk what is the format for
What if you try with: queries: "[equal (userId, "$userId"), equal(movieId, "$movieId")]"
Rank 3: Container
Yeah ive already try this :
const GET_LIKE_STATE = gql`
query GetLikeState($userId: String!, $movieId: String!) {
like: 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")]"
) {
documents {
_id
}
}
}
`;
but i got :
GraphQLError: Syntax Error: Expected Name, found "$".
Rank 3: Container
This is a tricky situation ahah because Ive no idea of the syntaxe so I try different thing without success
What if you try this:
const getLikeState = gql` query GetLikeState($userId: String!, $movieId: String!, $databaseId: String!, $collectionId: String!) { like: databasesListDocuments( databaseId: $databaseId, collectionId: $collectionId, queries: "[equal (userId, $userId), equal(movieId, $movieId)]" ) { documents { _id } } }`;Try this I've moved the databaseId and collectionId to be a graphql var so you don't mix sintaxes, give a try and let me know if it works or do you have the same error
You have to pass $databaseId and $collectionId in your query
Rank 3: Container
Ive try but still getting these errors :
{
"errors": [
{
"message": "Variable \"$userId\" is never used in operation \"GetLikeState\".",
"extensions": {
"category": "graphql"
},
"locations": [
{
"line": 1,
"column": 20
}
]
},
{
"message": "Variable \"$movieId\" is never used in operation \"GetLikeState\".",
"extensions": {
"category": "graphql"
},
"locations": [
{
"line": 1,
"column": 38
}
]
}
]
}
Rank 3: Container
Idk why Apollo isnt able to find the userId variable inside a queries
Rank 3: Container
This works (without variable) :
const GET_LIKE_STATE = gql`
query GetLikeState {
like: databasesListDocuments(
databaseId: "${String(process.env.NEXT_PUBLIC_APPWRITE_DATABASE_USERS)}",
collectionId: "${String(process.env.NEXT_PUBLIC_APPWRITE_COLLECTION_MOVIE_LIKED)}",
queries: ["equal(userId, 64abdd24ace0ed78ab19)", "equal(movieId, 545611)"]
) {
documents {
_id
}
}
}
`;
Rank 3: Container
Apollo Client and Appwrite
So can you note a difference between the working request and the one with error in the network tab?
Rank 3: Container
Well Ive discuss with Apollo Client team and the 'problem' (is actually not a problem but just how Appwrite Graphql system design is made). If I do that its working :
const GET_LIKE_STATE = gql`
query GetLikeState($queries: [String!]!) {
like: databasesListDocuments(
databaseId: "${String(process.env.NEXT_PUBLIC_APPWRITE_DATABASE_USERS)}",
collectionId: "${String(process.env.NEXT_PUBLIC_APPWRITE_COLLECTION_MOVIE_LIKED)}",
queries: $queries
) {
documents {
_id
}
}
}
`;
const { loading: isLoading, error: isError, data: isLiked } = useQuery(GET_LIKE_STATE, {
variables: {
queries: [`equal(userId, ${user?.$id})`, `equal(movieId, ${movieId})`]
}
})
Rank 3: Container
Mhh graphql seems to be slower than api queries. With Apollo Client and batching, one graphql query for getting all rating and like state for post takes around 89sec while multiple api queries take around 83sec in total (11s each one)