How to use the graphql-tools/dist/transforms/visitSchema.visitSchema 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 artsy / metaphysics / src / schema / v2 / FilterFields.ts View on Github external
public transformSchema(schema: GraphQLSchema): GraphQLSchema {
    const newSchema = visitSchema(schema, {
      [VisitSchemaKind.OBJECT_TYPE]: ((type: GraphQLObjectType) => {
        const fields = this.transformFields(type)
        if (fields) {
          // Leave type out if it's entirely empty after filtering fields.
          if (Object.keys(fields).length === 0) {
            return null
          } else {
            return new GraphQLObjectType({
              fields,
              name: type.name,
              description: type.description,
              astNode: type.astNode,
              extensionASTNodes: type.extensionASTNodes,
              isTypeOf: type.isTypeOf,
              interfaces: type.getInterfaces(),
            })
github apollo-model / apollo-model / packages / schema-filter / src / index.js View on Github external
return new GraphQLInterfaceType({
            name: type.name,
            // description: type.description,
            astNode: type.astNode,
            // isTypeOf: type.isTypeOf,
            fields: () =>
              fieldMapToFieldConfigMap(groupedFields[true], resolveType),
          });

          return undefined;
        },
      });

      //remove null from interfaces after first transformation
      newSchema = visitSchema(newSchema, {
        [VisitSchemaKind.OBJECT_TYPE]: type => {
          const interfaces = type.getInterfaces();
          let filteredInterfaces = interfaces.filter(iface => iface);

          if (filteredInterfaces.length === interfaces.length) {
            return undefined;
          }

          const fields = type.getFields();

          return new GraphQLObjectType({
            name: type.name,
            description: type.description,
            astNode: type.astNode,
            isTypeOf: type.isTypeOf,
            fields: () => fieldMapToFieldConfigMap(fields, resolveType, true),
github apollo-model / apollo-model / packages / schema-filter / src / index.js View on Github external
astNode: type.astNode,
            isTypeOf: type.isTypeOf,
            fields: () => fieldMapToFieldConfigMap(fields, resolveType, true),
            interfaces: () => filteredInterfaces,
          });

          return undefined;
        },
      });

      // visitSchema remove type if every field has been removed. But is doesn't remove types recursively
      let smthRemoved;
      do {
        smthRemoved = false;

        newSchema = visitSchema(newSchema, {
          [VisitSchemaKind.OBJECT_TYPE]: type => {
            if (Object.keys(type.getFields()).length === 0) {
              smthRemoved = true;
              return null;
            }
            return undefined;
          },
          [VisitSchemaKind.INPUT_OBJECT_TYPE]: type => {
            if (Object.keys(type.getFields()).length === 0) {
              smthRemoved = true;
              return null;
            }
            return undefined;
          },
          [VisitSchemaKind.INTERFACE_TYPE]: type => {
            if (Object.keys(type.getFields()).length === 0) {
github artsy / metaphysics / src / schema / v2 / transforms / FilterFields.ts View on Github external
public transformSchema(schema: GraphQLSchema): GraphQLSchema {
    const newSchema = visitSchema(schema, {
      [VisitSchemaKind.OBJECT_TYPE]: ((type: GraphQLObjectType) => {
        const fields = this.transformFields(type)
        if (fields) {
          // Leave type out if it's entirely empty after filtering fields.
          if (Object.keys(fields).length === 0) {
            return null
          } else {
            return new GraphQLObjectType({
              fields,
              name: type.name,
              description: type.description,
              astNode: type.astNode,
              extensionASTNodes: type.extensionASTNodes,
              isTypeOf: type.isTypeOf,
              interfaces: type.getInterfaces(),
            })
github apollo-model / apollo-model / packages / schema-filter / src / index.js View on Github external
transformSchema(schema) {
      defaults = DefaultFields();

      let newSchema = visitSchema(schema, {
        [VisitSchemaKind.OBJECT_TYPE]: type => {
          const groupedFields = groupFields(
            field => filterFields(type, field),
            type.getFields()
          );

          if (!groupedFields[false]) {
            return undefined;
          }
          if (!groupedFields[true]) return null;

          const interfaces = type.getInterfaces();

          return new GraphQLObjectType({
            name: type.name,
            description: type.description,
github artsy / metaphysics / src / schema / v2 / RemoveDeprecatedFields.ts View on Github external
public transformSchema(schema: GraphQLSchema): GraphQLSchema {
    const newSchema = visitSchema(schema, {
      [VisitSchemaKind.OBJECT_TYPE]: ((type: GraphQLObjectType) => {
        return new GraphQLObjectType({
          name: type.name,
          description: type.description,
          astNode: type.astNode,
          fields: this.transformFields(type),
          extensionASTNodes: type.extensionASTNodes,
          isTypeOf: type.isTypeOf,
          interfaces: type.getInterfaces(),
        })
      }) as TypeVisitor,

      [VisitSchemaKind.INTERFACE_TYPE]: ((type: GraphQLInterfaceType) => {
        return new GraphQLInterfaceType({
          name: type.name,
          description: type.description,
github artsy / metaphysics / src / schema / v2 / RenameFields.ts View on Github external
public transformSchema(schema: GraphQLSchema): GraphQLSchema {
    const newSchema = visitSchema(schema, {
      [VisitSchemaKind.OBJECT_TYPE]: ((type: GraphQLObjectType) => {
        const fields = this.transformFields(type)
        return (
          fields &&
          new GraphQLObjectType({
            fields,
            name: type.name,
            description: type.description,
            astNode: type.astNode,
            extensionASTNodes: type.extensionASTNodes,
            isTypeOf: type.isTypeOf,
            interfaces: type.getInterfaces(),
          })
        )
      }) as TypeVisitor,
github artsy / metaphysics / src / schema / v2 / transforms / RenameArguments.ts View on Github external
public transformSchema(schema: GraphQLSchema): GraphQLSchema {
    const newSchema = visitSchema(schema, {
      [VisitSchemaKind.OBJECT_TYPE]: ((type: GraphQLObjectType) => {
        return new GraphQLObjectType({
          name: type.name,
          description: type.description,
          astNode: type.astNode,
          fields: this.transformFields(type),
          extensionASTNodes: type.extensionASTNodes,
          isTypeOf: type.isTypeOf,
          interfaces: type.getInterfaces(),
        })
      }) as TypeVisitor,

      [VisitSchemaKind.INTERFACE_TYPE]: ((type: GraphQLInterfaceType) => {
        return new GraphQLInterfaceType({
          name: type.name,
          description: type.description,
github artsy / metaphysics / src / lib / stitching / exchange / transformers / replaceCommerceDateTimeType.ts View on Github external
public transformSchema(schema: GraphQLSchema): GraphQLSchema {
    const newSchema = visitSchema(schema, {
      [VisitSchemaKind.OBJECT_TYPE]: ((type: GraphQLObjectType) => {
        const fields = this.transformFields(type)
        return (
          fields &&
          new GraphQLObjectType({
            fields,
            name: type.name,
            description: type.description,
            astNode: type.astNode,
            extensionASTNodes: type.extensionASTNodes,
            isTypeOf: type.isTypeOf,
            interfaces: type.getInterfaces(),
          })
        )
      }) as TypeVisitor,