@graphql-tools/schema
References
Interfaces
Type Aliases
Functions
- addResolversToSchema
- assertResolversPresent
- chainResolvers
- checkForResolveTypeResolver
- extendResolversFromInterfaces
- makeExecutableSchema
- mergeSchemas
References
extractExtensionsFromSchema
Re-exports extractExtensionsFromSchema
Type Aliases
MergeSchemasConfig
Ƭ MergeSchemasConfig<T
>: Partial
<IExecutableSchemaDefinition
<T
>> & { schemas?
: GraphQLSchema
[] }
Configuration object for schema merging
Type parameters
Name | Type |
---|---|
T | any |
Defined in
packages/schema/src/merge-schemas.ts:17
Functions
addResolversToSchema
▸ addResolversToSchema(«destructured»
): GraphQLSchema
Parameters
Name | Type |
---|---|
«destructured» | IAddResolversToSchemaOptions |
Returns
GraphQLSchema
Defined in
packages/schema/src/addResolversToSchema.ts:32
assertResolversPresent
▸ assertResolversPresent(schema
, resolverValidationOptions?
): void
Parameters
Name | Type |
---|---|
schema | GraphQLSchema |
resolverValidationOptions | IResolverValidationOptions |
Returns
void
Defined in
packages/schema/src/assertResolversPresent.ts:4
chainResolvers
▸ chainResolvers<TArgs
>(resolvers
): (root
: any
, args
: TArgs
, ctx
: any
, info
: GraphQLResolveInfo
) => any
Type parameters
Name | Type |
---|---|
TArgs | extends Object |
Parameters
Name | Type |
---|---|
resolvers | Maybe <GraphQLFieldResolver <any , any , TArgs >>[] |
Returns
fn
▸ (root
, args
, ctx
, info
): any
Parameters
Name | Type |
---|---|
root | any |
args | TArgs |
ctx | any |
info | GraphQLResolveInfo |
Returns
any
Defined in
packages/schema/src/chainResolvers.ts:4
checkForResolveTypeResolver
▸ checkForResolveTypeResolver(schema
, requireResolversForResolveType?
): void
Parameters
Name | Type |
---|---|
schema | GraphQLSchema |
requireResolversForResolveType? | ValidatorBehavior |
Returns
void
Defined in
packages/schema/src/checkForResolveTypeResolver.ts:5
extendResolversFromInterfaces
▸ extendResolversFromInterfaces(schema
, resolvers
): IResolvers
Parameters
Name | Type |
---|---|
schema | GraphQLSchema |
resolvers | IResolvers |
Returns
Defined in
packages/schema/src/extendResolversFromInterfaces.ts:4
makeExecutableSchema
▸ makeExecutableSchema<TContext
>(«destructured»
): GraphQLSchema
Builds a schema from the provided type definitions and resolvers.
The type definitions are written using Schema Definition Language (SDL). They
can be provided as a string, a DocumentNode
, a function, or an array of any
of these. If a function is provided, it will be passed no arguments and
should return an array of strings or DocumentNode
s.
Note: You can use GraphQL magic comment provide additional syntax highlighting in your editor (with the appropriate editor plugin).
const typeDefs = /* GraphQL */ `
type Query {
posts: [Post]
author(id: Int!): Author
}
`;
The resolvers
object should be a map of type names to nested object, which
themselves map the type’s fields to their appropriate resolvers.
See the Resolvers section of the documentation for more details.
const resolvers = {
Query: {
posts: (obj, args, ctx, info) => getAllPosts(),
author: (obj, args, ctx, info) => getAuthorById(args.id)
}
};
Once you’ve defined both the typeDefs
and resolvers
, you can create your
schema:
const schema = makeExecutableSchema({
typeDefs,
resolvers,
})
Type parameters
Name | Type |
---|---|
TContext | any |
Parameters
Name | Type |
---|---|
«destructured» | IExecutableSchemaDefinition <TContext > |
Returns
GraphQLSchema
Defined in
packages/schema/src/makeExecutableSchema.ts:51
mergeSchemas
▸ mergeSchemas(config
): GraphQLSchema
Synchronously merges multiple schemas, typeDefinitions and/or resolvers into a single schema.
Parameters
Name | Type | Description |
---|---|---|
config | MergeSchemasConfig <any > | Configuration object |
Returns
GraphQLSchema