Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
});
if (this.typeDefs.includes('@connection')) {
if (!this.config.generateConnections) {
throw new Error('Generate Connections must be true to use connection directive');
}
// don't want to attempt this if we didn't create the necessary types yet
if (this.typeDefs.includes('Connection') && this.typeDefs.includes('Edge') && this.typeDefs.includes('PageInfo')) {
SchemaDirectiveVisitor.visitSchemaDirectives(this.schema, {
connection: ConnectionDirective
});
}
}
const typeMap = this.schema.getTypeMap();
if (this.typeDefs.includes('@model')) {
SchemaDirectiveVisitor.visitSchemaDirectives(this.schema, {
model: ModelDirective
});
}
else {
Object.keys(typeMap).forEach(name => {
const type = typeMap[name];
if (isObjectType(type) && type.name !== 'PageInfo' && !type.name.includes('__') && !type.name.endsWith('Aggregate') && !type.name.endsWith('Connection') && !type.name.endsWith('Edge') && !type.name.endsWith('Payload') && !(type.name.toLowerCase() === 'query') && !(type.name.toLowerCase() === 'mutation') && !(type.name.toLowerCase() === 'subscription')) {
type['_interfaces'].push(typeMap.Node);
has(this.schema, '_implementations.Node') ? this.schema['_implementations'].Node.push(type) : set(this.schema, '_implementations.Node', [type]);
}
});
}
return this.schema;
};
this.getSchema = () => {
relation: RelationDirective,
default: DefaultDirective,
unique: UniqueDirective
},
resolverValidationOptions: {
requireResolversForResolveType: false
}
});
if (this.typeDefs.includes('@connection')) {
if (!this.config.generateConnections) {
throw new Error('Generate Connections must be true to use connection directive');
}
// don't want to attempt this if we didn't create the necessary types yet
if (this.typeDefs.includes('Connection') && this.typeDefs.includes('Edge') && this.typeDefs.includes('PageInfo')) {
SchemaDirectiveVisitor.visitSchemaDirectives(this.schema, {
connection: ConnectionDirective
});
}
}
const typeMap = this.schema.getTypeMap();
if (this.typeDefs.includes('@model')) {
SchemaDirectiveVisitor.visitSchemaDirectives(this.schema, {
model: ModelDirective
});
} else {
Object.keys(typeMap).forEach(name => {
const type = typeMap[name];
if (isObjectType(type) && type.name !== 'PageInfo' && !type.name.includes('__') && !type.name.endsWith('Aggregate') && !type.name.endsWith('Connection') && !type.name.endsWith('Edge') && !type.name.endsWith('Payload') && !type.name.endsWith('PreviousValues') && !(type.name.toLowerCase() === 'query') && !(type.name.toLowerCase() === 'mutation') && !(type.name.toLowerCase() === 'subscription')) {
type['_interfaces'].push(typeMap.Node);
export default function getTenantSchema() {
const schema = loadSchema("tenant", resolvers as IResolvers);
// Attach the directive resolvers.
attachDirectiveResolvers(schema, { auth });
// Attach the constraint directive.
SchemaDirectiveVisitor.visitSchemaDirectives(schema, {
constraint,
});
return schema;
}
}
@Resolver(of => SampleObjectType)
class SampleObjectTypeResolver {
@FieldResolver()
@Directive("@append")
fieldResolverWithAppendDefinition(): string {
return "hello";
}
}
schema = await buildSchema({
resolvers: [SampleResolver, SampleObjectTypeResolver],
});
SchemaDirectiveVisitor.visitSchemaDirectives(schema, {
upper: UpperCaseDirective,
append: AppendDirective,
});
});
graphQLSchemaTypeFieldMap[graphQLSchemaTypeFieldName];
if (!graphQLSchemaTypeField.astNode) {
const astNode = graphQLCustomTypeDef.fields.find(
field => field.name.value === graphQLSchemaTypeFieldName
);
if (astNode) {
graphQLSchemaTypeField.astNode = astNode;
}
}
}
);
}
}
});
SchemaDirectiveVisitor.visitSchemaDirectives(
this.graphQLSchema,
this.graphQLSchemaDirectives
);
} else {
this.graphQLSchema = this.graphQLAutoSchema;
}
return this.graphQLSchema;
}
export const addTypeDefsToSchema = (typeDefs: string): GraphQLSchema => {
if (!typeDefs || typeDefs.indexOf('Query') < 0) {
typeDefs = 'type Query {noop:Int}';
}
schema = makeExecutableSchema({
typeDefs: defaultTypeDefs + typeDefs,
schemaDirectives: {
display: DisplayDirective,
relation: RelationDirective
}
});
SchemaDirectiveVisitor.visitSchemaDirectives(schema, {
model: ModelDirective
});
return schema;
};