How to use the graphql-tools.RenameTypes function in graphql-tools

To help you get started, we’ve selected a few graphql-tools 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 atomist / automation-client / bin / gql-gen.ts View on Github external
async function main(): Promise {
    try {
        const cwd = process.cwd();
        const lib = await libDir(cwd);

        // check if the project has a custom schema
        const customSchemaLocation = path.join(lib, "graphql", "schema.json");
        const defaultSchemaLocation = path.resolve(__dirname, "..", "lib", "graph", "schema.json");
        const schema = (await fs.pathExists(customSchemaLocation)) ? customSchemaLocation : defaultSchemaLocation;
        const transform = new RenameTypes(name => {
            switch (name) {
                case "Fingerprint":
                case "PushImpact":
                    return `Deprecated${name}`;
                default:
                    return undefined;
            }
        });

        const gqlGenOutput = path.join(lib, "typings", "types.ts");
        const graphQlGlob = `${lib}/graphql/!(ingester)/*.graphql`;

        const config: Types.GenerateOptions = {
            schema: parse(printSchema(transform.transformSchema(await loadSchema(schema)))),
            filename: gqlGenOutput,
            plugins: [{
github slicknode / slicknode / src / validation / validateSchema.ts View on Github external
function transformRemoteSchema(schema: string, namespace: string | null): string {
  let transformedSchema = buildSchema(schema);
  transformedSchema = transformSchema(transformedSchema, [
    new RenameTypes(
      (name) => namespace ? `${namespace}_${name}` : name,
    ),
    new RenameRootFields(
      ((operation, name) => namespace ? `${namespace}_${name}` : name),
    ),
  ]);
  const rootTypeNames: string[] = [];
  if (transformedSchema.getMutationType()) {
    rootTypeNames.push(transformedSchema.getMutationType()!.name);
  }
  if (transformedSchema.getQueryType()) {
    rootTypeNames.push(transformedSchema.getQueryType()!.name);
  }
  // Once subscriptions are supported, do the same here...
  let transformedSchemaDoc = parse(printSchema(transformedSchema));
github gridsome / gridsome / packages / source-graphql / index.js View on Github external
namespaceSchema (schema, fieldName, typeName) {
    return transformSchema(schema, [
      new StripNonQueryTransform(),
      new RenameTypes(name => `${typeName}_${name}`),
      new NamespaceUnderFieldTransform(typeName, fieldName)
    ])
  }
}
github nilshartmann / graphql-examples / schema-stitching / schema-stitcher / src / Stitcher.ts View on Github external
function renameSystemInfo(schema: GraphQLSchema, systemName: String) {
  return transformSchema(schema, [
    new RenameTypes((name: string) => (name === "ProcessInfo" ? `${systemName}Status` : undefined)),
    new RenameRootFields(
      (_operation: string, name: string) =>
        name === "ping" ? `${systemName.substring(0, 1).toLowerCase()}${systemName.substring(1)}Status` : name
    )
  ]);
}
github cdmbase / fullstack-pro / servers / backend-server / src / api / schema-builder.ts View on Github external
private patchSchema(schema: GraphQLSchema, systemName: string) {
        return transformSchema(schema, [
            new RenameTypes((name: string) => (name === 'StatusInfo' ? `${systemName}StatusInfo` : undefined)),
            new RenameRootFields(
                (_operation: string, name: string) =>
                    name === 'status' ? `${systemName.substring(0, 1).toLowerCase()}${systemName.substring(1)}Status` : name,
            ),
        ]);
    }
github jakedohm / gridsome-source-craftql / index.js View on Github external
namespaceSchema(schema, fieldName, typeName) {
    return transformSchema(schema, [
      new StripNonQueryTransform(),
      new RenameTypes(name => `${typeName}_${name}`),
      new NamespaceUnderFieldTransform(typeName, fieldName),
    ])
  }
}