Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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;
}
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;
},