Back

Trying to use GraphQl variables

  • 0
  • GraphQL
  • Web
Luky
28 Aug, 2023, 16:55

Hi hope you doing well !

I cant seam to figure how to use environments variables.

TypeScript
const response = await graphql.query({
    query: `query {
    databasesGetDocument(
      databaseId: "social"
      collectionId: "cards"
      documentId: $documentId
    ) {
      data
      _id
      _collectionId
      _databaseId
      _createdAt
      _updatedAt
      _permissions
    }
  }`,
    variables: {
        documentId: params.cardId,
    },
});

Thi give me the following GraphQl error :

TypeScript
Variable "$documentId" is not defined.

params.cardId is correctly set

TL;DR
The user is asking for help with using GraphQL variables. They have provided a code snippet and are experiencing an error message saying "Variable '$documentId' is not defined." They believe that the variable `params.cardId` is correctly set. They are seeking guidance on how to fix this issue. Solution: The user needs to add the variable declaration in the GraphQL query. They should modify the query to include the declaration of the `$documentId` variable: ```javascript query GetDocument($documentId: String!) { databasesGetDocument( databaseId: "social" collectionId: "cards" documentId: $
joeyouss
28 Aug, 2023, 18:00

can you see this once and let me know if this helps? https://appwrite.io/docs/graphql#sdk-usage

Luky
28 Aug, 2023, 18:04

Thanks, I already saw it. But i dont see my mistake :/

joeyouss
28 Aug, 2023, 18:33

You need to add GetDocument($documentId: String)

TypeScript

const response = await graphql.query({
    query: `query GetDocument($documentId: String!) {
    databasesGetDocument(
      databaseId: "social"
      collectionId: "cards"
      documentId: $documentId
    ) {
      data
      _id
      _collectionId
      _databaseId
      _createdAt
      _updatedAt
      _permissions
    }
  }`,
    variables: {
        documentId: params.cardId,
    },
});```
joeyouss
28 Aug, 2023, 18:34

Can you try it once @Luky ?

Luky
28 Aug, 2023, 23:17

I ended by not using qraphQl i moved to it trying to do join like queries :/

Luky
28 Aug, 2023, 23:17

But this doesn't seem possible

Luky
28 Aug, 2023, 23:17

Thanks for your help !

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more