Skip to content

Get collections data via JS – GraphQL #4460

Answered by eliasu
eliasu asked this question in Q&A
Discussion options

You must be logged in to vote

Thanks for the direction. I could figure it out … it was quote a challenge to get everything up and running, but now it works. If anybody is looking for the same … heres how i've done it ;)

1. Activate GraphQL

  • Either go to your .env file and set a variable of STATAMIC_GRAPHQL_ENABLED=true
  • Or go to config/statamic/graphql.php and under GraphQL set 'enabled' => true,

2. Install Helpers

There are many ways to retrieve GraphQL messages. Have a look at @jasonvarga post. There are some good links to start.
I used this npm add graphql-request graphql See documentation.

3. What to do within JS?

  • Import the library at the top of your file
import { GraphQLClient, gql } from 'graphql-request'
  • Cr…

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by eliasu
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants