How to use the relay-compiler.GraphQLCompilerContext function in relay-compiler

To help you get started, weโ€™ve selected a few relay-compiler 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 n1ru4l / graphql-codegen-relay-plugins / packages / graphql-codegen-relay-optimizer-plugin / src / index.ts View on Github external
const adjustedSchema = transformASTSchema(schema, [
    /* GraphQL */ `
      directive @connection(key: String!) on FIELD
      directive @client on FIELD
    `
  ]);
  const documentAsts = documents.reduce(
    (prev, v) => {
      return [...prev, ...v.content.definitions];
    },
    [] as DefinitionNode[]
  );

  const relayDocuments = RelayParser.transform(adjustedSchema, documentAsts);

  const fragmentCompilerContext = new GraphQLCompilerContext(
    adjustedSchema
  ).addAll(relayDocuments);

  const fragmentDocuments = fragmentCompilerContext
    .applyTransforms([
      RelayApplyFragmentArgumentTransform.transform,
      FlattenTransform.transformWithOptions({ flattenAbstractTypes: false }),
      SkipRedundantNodesTransform.transform
    ])
    .documents()
    .filter(doc => doc.kind === "Fragment");

  const queryCompilerContext = new GraphQLCompilerContext(adjustedSchema)
    .addAll(relayDocuments)
    .applyTransforms([
      RelayApplyFragmentArgumentTransform.transform,
github facebook / relay / packages / relay-test-utils / RelayModernTestUtils.js View on Github external
function generate(
  text: string,
  schema: GraphQLSchema,
  transforms: RelayCompilerTransforms,
): {[key: string]: GeneratedNode} {
  const {
    compileRelayArtifacts,
    GraphQLCompilerContext,
    IRTransforms,
    transformASTSchema,
  } = require('relay-compiler');

  const relaySchema = transformASTSchema(schema, IRTransforms.schemaExtensions);
  const compilerContext = new GraphQLCompilerContext(
    schema,
    relaySchema,
  ).addAll(parseGraphQLText(relaySchema, text).definitions);
  const documentMap = {};
  compileRelayArtifacts(compilerContext, transforms).forEach(
    ([_definition, node]) => {
      documentMap[
        node.kind === 'Request' ? node.params.name : node.name
      ] = node;
    },
  );
  return documentMap;
}
github facebook / relay / packages / relay-test-utils-internal / TestCompiler.js View on Github external
function generate(
  text: string,
  schema: GraphQLSchema,
  transforms: RelayCompilerTransforms,
  moduleMap: ?{[string]: mixed},
): {[key: string]: GeneratedNode} {
  const relaySchema = transformASTSchema(schema, IRTransforms.schemaExtensions);
  const {definitions, schema: extendedSchema} = parseGraphQLText(
    relaySchema,
    text,
  );
  const compilerContext = new GraphQLCompilerContext(
    Schema.DEPRECATED__create(schema, extendedSchema),
  ).addAll(definitions);
  const documentMap = {};
  compileRelayArtifacts(compilerContext, transforms).forEach(
    ([_definition, node]) => {
      const transformedNode =
        moduleMap != null ? CodeMarker.transform(node, moduleMap) : node;
      documentMap[
        node.kind === 'Request' ? node.params.name : node.name
      ] = transformedNode;
    },
  );
  return documentMap;
}
github n1ru4l / graphql-codegen-relay-plugins / packages / graphql-codegen-relay-plugin / index.js View on Github external
const adjustedSchema = transformASTSchema(schema, [
    `
  directive @connection(
    key: String!
  ) on FIELD
  directive @client on FIELD
  `
  ]);

  const documentAsts = documents.reduce((prev, v) => {
    return [...prev, ...v.content.definitions];
  }, []);

  const relayDocuments = RelayParser.transform(adjustedSchema, documentAsts);

  const fragmentCompilerContext = new GraphQLCompilerContext(
    adjustedSchema
  ).addAll(relayDocuments);

  const fragmentDocuments = fragmentCompilerContext
    .documents()
    .filter(doc => doc.kind === "Fragment");

  fragmentCompilerContext.applyTransforms([
    RelayApplyFragmentArgumentTransform.transform,
    FlattenTransform.transformWithOptions({ flattenAbstractTypes: true })
  ]);

  const queryDocuments = fragmentCompilerContext
    .documents()
    .filter(doc => doc.kind === "Root" && doc.operation === "query");