graphql#stripIgnoredCharacters JavaScript Examples

The following examples show how to use graphql#stripIgnoredCharacters. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: index.js    From merkur with MIT License 5 votes vote down vote up
function graphqlClientAPI() {
  return {
    graphql: {
      async request(widget, operation, variables = {}, options = {}) {
        const { endpointUrl, entityClasses } = widget.$in.graphqlClient;
        const { headers = {}, body = {}, ...restOptions } = options;

        operation = addTypenameToSelections(operation);

        const { response } = await widget.http.request({
          url: endpointUrl,
          method: 'POST',
          headers: {
            'Content-Type': 'application/json',
            ...headers,
          },
          body: {
            query: stripIgnoredCharacters(print(operation)),
            variables,
            ...body,
          },
          ...restOptions,
        });

        const { errors, data = {} } = response.body;
        if (errors) {
          if (
            Array.isArray(errors) &&
            errors.some((error) => error.status === 'unauthorized')
          ) {
            return Promise.reject(
              new UnauthorizedError(`Unauthorized Error`, { errors, data })
            );
          }

          return Promise.reject(
            new GraphQLError(`Api Error`, { errors, data })
          );
        }

        return processResponseData(data, entityClasses);
      },
    },
  };
}