Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return new GraphQLObjectType({
fields,
name: type.name,
description: type.description,
astNode: type.astNode,
extensionASTNodes: type.extensionASTNodes,
isTypeOf: type.isTypeOf,
interfaces: type.getInterfaces(),
})
}
} else {
return undefined
}
}) as TypeVisitor,
[VisitSchemaKind.INTERFACE_TYPE]: ((type: GraphQLInterfaceType) => {
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 GraphQLInterfaceType({
fields,
name: type.name,
description: type.description,
astNode: type.astNode,
resolveType: type.resolveType,
extensionASTNodes: type.extensionASTNodes,
})
}
} else {
return new GraphQLObjectType({
fields,
name: type.name,
description: type.description,
astNode: type.astNode,
extensionASTNodes: type.extensionASTNodes,
isTypeOf: type.isTypeOf,
interfaces: type.getInterfaces(),
})
}
} else {
return undefined
}
}) as TypeVisitor,
[VisitSchemaKind.INTERFACE_TYPE]: ((type: GraphQLInterfaceType) => {
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 GraphQLInterfaceType({
fields,
name: type.name,
description: type.description,
astNode: type.astNode,
resolveType: type.resolveType,
extensionASTNodes: type.extensionASTNodes,
})
}
} else {
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) {
smthRemoved = true;
return null;
}
return undefined;
},
});
} while (smthRemoved);
Object.values(schema.getTypeMap()).forEach(type => {
if (type.name.startsWith('__')) return;
if (type instanceof GraphQLInputObjectType) {
Object.values(type.getFields()).forEach(field => {
// if (
// !newSchema.getTypeMap()[type.name] ||
// !newSchema.getTypeMap()[type.name].getFields()[field.name]
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,
astNode: type.astNode,
fields: this.transformFields(type),
resolveType: type.resolveType,
extensionASTNodes: type.extensionASTNodes,
})
}) as TypeVisitor,
})
return newSchema
}
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,
[VisitSchemaKind.INTERFACE_TYPE]: ((type: GraphQLInterfaceType) => {
const fields = this.transformFields(type)
return (
fields &&
new GraphQLInterfaceType({
fields,
name: type.name,
description: type.description,
astNode: type.astNode,
resolveType: type.resolveType,
extensionASTNodes: type.extensionASTNodes,
})
)
}) as TypeVisitor,
})
return newSchema
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,
astNode: type.astNode,
fields: this.transformFields(type),
resolveType: type.resolveType,
extensionASTNodes: type.extensionASTNodes,
})
}) as TypeVisitor,
})
return newSchema
}
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,
[VisitSchemaKind.INTERFACE_TYPE]: ((type: GraphQLInterfaceType) => {
const fields = this.transformFields(type)
return (
fields &&
new GraphQLInterfaceType({
fields,
name: type.name,
description: type.description,
astNode: type.astNode,
resolveType: type.resolveType,
extensionASTNodes: type.extensionASTNodes,
})
)
}) as TypeVisitor,
})
this.newSchema = newSchema