mirror of
https://github.com/vale981/apollo-server
synced 2025-03-06 10:11:40 -05:00
docs: remove old way of adding schema directives
This commit is contained in:
parent
531162c693
commit
d84061b148
1 changed files with 0 additions and 42 deletions
|
@ -614,45 +614,3 @@ As its name suggests, the `SchemaDirectiveVisitor` abstraction is specifically d
|
|||
While directive syntax can also appear in GraphQL queries sent from the client, implementing query directives would require runtime transformation of query documents. We have deliberately restricted this implementation to transformations that take place when you call the `makeExecutableSchema` function—that is, at schema construction time.
|
||||
|
||||
We believe confining this logic to your schema is more sustainable than burdening your clients with it, though you can probably imagine a similar sort of abstraction for implementing query directives. If that possibility becomes a desire that becomes a need for you, let us know, and we may consider supporting query directives in a future version of these tools.
|
||||
|
||||
## What about `directiveResolvers`?
|
||||
|
||||
Before `SchemaDirectiveVisitor` was implemented, the `makeExecutableSchema` function took a `directiveResolvers` option that could be used for implementing certain kinds of `@directive`s on fields that have resolver functions.
|
||||
|
||||
The new abstraction is more general, since it can visit any kind of schema syntax, and do much more than just wrap resolver functions. However, the old `directiveResolvers` API has been [left in place](directive-resolvers.html) for backwards compatibility, though it is now implemented in terms of `SchemaDirectiveVisitor`:
|
||||
|
||||
```typescript
|
||||
function attachDirectiveResolvers(
|
||||
schema: GraphQLSchema,
|
||||
directiveResolvers: IDirectiveResolvers<any, any>,
|
||||
) {
|
||||
const schemaDirectives = Object.create(null);
|
||||
|
||||
Object.keys(directiveResolvers).forEach(directiveName => {
|
||||
schemaDirectives[directiveName] = class extends SchemaDirectiveVisitor {
|
||||
public visitFieldDefinition(field: GraphQLField<any, any>) {
|
||||
const resolver = directiveResolvers[directiveName];
|
||||
const originalResolver = field.resolve || defaultFieldResolver;
|
||||
const directiveArgs = this.args;
|
||||
field.resolve = (...args: any[]) => {
|
||||
const [source, /* original args */, context, info] = args;
|
||||
return resolver(
|
||||
async () => originalResolver.apply(field, args),
|
||||
source,
|
||||
directiveArgs,
|
||||
context,
|
||||
info,
|
||||
);
|
||||
};
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
SchemaDirectiveVisitor.visitSchemaDirectives(
|
||||
schema,
|
||||
schemaDirectives,
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
Existing code that uses `directiveResolvers` should probably consider migrating to `SchemaDirectiveVisitor` if feasible, though we have no immediate plans to deprecate `directiveResolvers`.
|
||||
|
|
Loading…
Add table
Reference in a new issue