How to use the graphql-tool-utilities.compile function in graphql-tool-utilities

To help you get started, we’ve selected a few graphql-tool-utilities examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Shopify / graphql-tools-web / packages / graphql-fixtures / src / fill.ts View on Github external
return (request: GraphQLRequest) => {
      const {operationName, query} = request;

      const operation =
        (operationName && documentToOperation.get(operationName)) ||
        Object.values(compile(schema, normalizeDocument(query)).operations)[0];

      if (operationName != null) {
        documentToOperation.set(operationName, operation);
      }

      return fillObject(
        operation.rootType,
        operation.rootType,
        // the root type is kind of weird, since there is no "field" that
        // would be used in a resolver. For simplicity in the common case
        // we just hack this type to make it conform.
        [operation as any],
        data,
        request,
        context,
      ) as Data;
github Shopify / quilt / packages / jest-mock-apollo / src / MockApolloLink.ts View on Github external
{query, operationName = ''}: Operation,
  schema: GraphQLSchema,
) {
  if (query == null || operationName == null) {
    return data;
  }

  // For some reason, these documents do not have any details on the source,
  // which apollo-codegen depends on for top-level operations. This manually
  // adds some hacky references so that they are always at least defined.
  query.definitions.forEach(definition => {
    (definition as any).loc =
      definition.loc || ({source: {name: 'GraphQL request'}} as Location);
  });

  const ast = compile(schema, query);
  const operation = ast.operations[operationName];

  return Object.keys(data).reduce(
    (all, key) => ({
      ...all,
      [key]: normalizeDataWithField(
        data[key],
        operation.fields &&
          operation.fields.find(({responseName}) => responseName === key),
      ),
    }),
    {},
  );
}
github Shopify / graphql-tools-web / packages / graphql-validate-fixtures / src / index.ts View on Github external
let schema: GraphQLSchema;

  try {
    schema = projectConfig.getSchema();
  } catch (error) {
    throw new Error(
      `Error parsing '${projectConfig.schemaPath}':\n\n${error.message.replace(
        /Syntax Error.*?\(.*?\) /,
        '',
      )}`,
    );
  }

  return {
    ast: compile(schema, document),
    config: projectConfig,
  };
}

graphql-tool-utilities

Common utilities for GraphQL developer tools

MIT
Latest version published 15 days ago

Package Health Score

87 / 100
Full package analysis

Similar packages