POC for consumption of GraphQL API in AEM

This POC defines that GraphQL API can be consumed by one of the following approach.

Apollo client can be used to consume a GraphQL endpoint in AEM by implementing the following steps:

Here is a sample code for consuming a GraphQL endpoint in AEM using Apollo client:

import { ApolloClient, gql, HttpLink, InMemoryCache } from 'apollo-boost';

const client = new ApolloClient({
  cache: new InMemoryCache(),
  link: new HttpLink({
  uri: 'https://your-gql-endpoint.com/graphql',
 }),
});

const query = gql '{ allCars { id make model year color price }';

client.query({query: query,}).then((data) => {console.log(data);
});

Leave a comment