Using GraphQL APIs

Liferay DXP’s GraphQL APIs are independent of clients and can be used with any GraphQL client you want. The only usual requirements are setting up the Authentication header using OAuth, Cookie, Basic, etc.

For JavaScript applications, we recommend using Apollo Client or graphql-request, like this:

const { GraphQLClient } = require('graphql-request');

const graphQLClient = new GraphQLClient('http://localhost:8080/o/graphql', {
    headers: {
        authorization: `Basic ${AUTHORIZATION_TOKEN}`
    }
});

const getDestinationsQuery = ` {
  destinations: contentSetContentSetElements(contentSetId: ${DESTINATION_CONTENTSET_ID}) {
    items {
        id
        title
    }
    page
    pageSize
    totalCount
  }
}`;

...

const response = await graphQLClient.request(getDestinationsQuery);

Here are several examples of JavaScript applications using GraphQL APIs:

« Multipart RequestsREST Builder »
Was this article helpful?
0 out of 0 found this helpful