Provides Apollo Client as a drupal library.
mylibrary:
version: 1.x
js:
js/mylibrary.js: {}
dependencies:
- apollo/client
- polyfill/babel
js/mylibrary.js
// ApollClient's server url defaults to /graphql, so this will connect to the
// local enpoint exposed by GraphQL module (https://drupal.org/project/graphql).
// See https://www.apollographql.com/docs/react/reference for available
// configuration options.
const client = new global.ApolloClient();
// Create a GraphQL query object by passing a tagged template literal to the gql
// function (provided by apollo/client). This particular query returns username
// of the currently logged in user.
const query = gql`
query {
currentUserContext{
... on UserUser {
name
}
}
}
`;
const result = await client.query({ query });
console.log(result);