Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public transformSchema(schema: GraphQLSchema) {
const builder = getBuilder(schema)
return visit(schema, {
[VisitSchemaKind.OBJECT_TYPE]: (type: GraphQLObjectType): GraphQLObjectType => {
if (type.name.match(this.typeName)) {
const config = type.toConfig()
// parseType
for (let fieldName in config.fields) {
if (fieldName.match(this.name)) {
config.fields[fieldName] = this.fieldTransform(config.fields[fieldName], {
type,
builder,
})
}
}
return new GraphQLObjectType(config)
}
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(),
})
}
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(),
})
}
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),
interfaces: () => filteredInterfaces,
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,
[VisitSchemaKind.INTERFACE_TYPE]: ((type: GraphQLInterfaceType) => {
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,
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,
[VisitSchemaKind.INTERFACE_TYPE]: ((type: GraphQLInterfaceType) => {
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,