apollographql / apollographql/federation
Custom directive not found in schema using @composeDirective
- Dominant language
- TypeScript
- Stars
- 725
- Forks
- 276
- Avg merge
- 1h 47m
- Merged PRs (30d)
- 1
Description
I user @`composeDirective` to preserve custom directive `@dateFormat` on supergraph.
I can see it on `supergraphqlSdl`, but can't find it in the parameter `requestcontext` of Apollo Server plugin `willSendResponse`.
Is it the expected behavior that this custom directive not in `schema.getDirectives()` after using` @composeDirective` ?
Can I get this custom directive in the plugin?
use dependencies
`"@apollo/gateway": "^2.1.1",
"@apollo/subgraph": "^2.1.1",
"apollo-server": "^3.10.2",`
Here is the subgraph
```
const typeDefs = gql`
extend schema
@link(url: "https://specs.apollo.dev/link/v1.0")
@link(url: "https://specs.apollo.dev/federation/v2.0", import: ["@composeDirective"])
@link(url: "https://specs.test.com/directives/v1.0", import: ["@dateFormat"])
@composeDirective(name: "@dateFormat")
directive @dateFormat(format: String = "mmmm d, yyyy") on FIELD_DIFINITION
type Color {
id: ID!
title: String!
value: String!
created(format: String): String! @dateFormat
}
type Query {
color(id: String): Color!
allColors: [Color!]!
}
`;
```
Here is the gateway and plugin. I can't get directive information from schema.getDirectives().
>
```
const start = async () => {
const server = new ApolloServer({
gateway,
subscriptions: true,
introspection: false,
formatError: (err) => { console.log(err.stack); return err },
plugins: [
ApolloServerPluginLandingPageGraphQLPlayground(),
{
async serverWillStart() {
return {
schemaDidLoadOrUpdate({ _apiSchema, coreSupergraphSdl }) {
if (coreSupergraphSdl) {
console.log(`The core schema is ${coreSupergraphSdl}`);
}
},
};
},
async requestDidStart(requestContext) {
console.log('Request started!');
return {
async willSendResponse(
requestContext,
){
console.log(JSON.stringify(requestContext.schema.getDirectives()));
console.log(`Can not find @dateDirective`);
}
}
},
}
],
});
```
Contributor guide
Research direction
Reproduce the issue with the provided subgraph SDL, gateway configuration, and Apollo Server plugin, then compare the composed supergraph SDL with schema.getDirectives() in willSendResponse. Trace how @composeDirective metadata is represented during gateway schema loading; done means the expected behavior is established and, if incorrect, covered by a regression test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- backend-api-design
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100