How to use graphql-tool-utilities - 6 common examples

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,
  };
}
github Shopify / graphql-tools-web / packages / graphql-typescript-definitions / src / print / document / index.ts View on Github external
return generate(t.file(t.program(fileBody), [], [])).code;
  }

  const context = new OperationContext(operation, ast, options, file);
  const partialContext = new OperationContext(
    operation,
    ast,
    {...options, partial: true},
    file,
  );

  let rootType: GraphQLObjectType;

  if (operation.operationType === OperationType.Query) {
    rootType = ast.schema.getQueryType() as any;
  } else if (operation.operationType === OperationType.Mutation) {
    rootType = ast.schema.getMutationType() as any;
  } else {
    rootType = ast.schema.getSubscriptionType() as any;
  }

  const variables =
    operation.variables.filter(isTypedVariable).length > 0
      ? context.export(variablesInterface(operation.variables, context))
      : null;

  const operationInterface = t.tsInterfaceDeclaration(
    t.identifier(context.typeName),
    null,
    null,
    tsInterfaceBodyForObjectField(
      operation,
github Shopify / graphql-tools-web / packages / graphql-typescript-definitions / src / print / document / index.ts View on Github external
}

    return generate(t.file(t.program(fileBody), [], [])).code;
  }

  const context = new OperationContext(operation, ast, options, file);
  const partialContext = new OperationContext(
    operation,
    ast,
    {...options, partial: true},
    file,
  );

  let rootType: GraphQLObjectType;

  if (operation.operationType === OperationType.Query) {
    rootType = ast.schema.getQueryType() as any;
  } else if (operation.operationType === OperationType.Mutation) {
    rootType = ast.schema.getMutationType() as any;
  } else {
    rootType = ast.schema.getSubscriptionType() as any;
  }

  const variables =
    operation.variables.filter(isTypedVariable).length > 0
      ? context.export(variablesInterface(operation.variables, context))
      : null;

  const operationInterface = t.tsInterfaceDeclaration(
    t.identifier(context.typeName),
    null,
    null,
github Shopify / graphql-tools-web / packages / graphql-typescript-definitions / src / print / document / context.ts View on Github external
get typeName() {
    let typeName: string;

    if (isOperation(this.operation)) {
      const {operationName, operationType} = this.operation;
      typeName = `${ucFirst(operationName)}${ucFirst(operationType)}Data`;
    } else {
      const {fragmentName} = this.operation;
      typeName = `${ucFirst(fragmentName)}FragmentData`;
    }

    return this.options.partial
      ? typeName.replace(/Data$/, 'PartialData')
      : typeName;
  }

graphql-tool-utilities

Common utilities for GraphQL developer tools

MIT
Latest version published 4 months ago

Package Health Score

56 / 100
Full package analysis

Similar packages