How to use the graphql-tools.SchemaDirectiveVisitor.visitSchemaDirectives 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 genie-team / graphql-genie / lib / GraphQLSchemaBuilder.js View on Github external
}
            });
            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 = () => {
github genie-team / graphql-genie / src / GraphQLSchemaBuilder.ts View on Github external
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);
github coralproject / talk / src / core / server / graph / tenant / schema / index.ts View on Github external
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;
}
github MichalLytek / type-graphql / tests / functional / directives.ts View on Github external
}

      @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,
      });
    });
github parse-community / parse-server / src / GraphQL / ParseGraphQLSchema.js View on Github external
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;
  }
github genie-team / graphql-genie / src / graphQLShema.ts View on Github external
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;
};