ardatan / ardatan/graphql-tools
Multiple directives not working in the sequence as defined in the graphql query
- Dominant language
- TypeScript
- Stars
- 5.4k
- Forks
- 830
- Avg merge
- 10h 59m
- Merged PRs (30d)
- 45
Description
### Issue workflow progress
_Progress of the issue based on the
[Contributor Workflow](https://github.com/the-guild-org/Stack/blob/master/CONTRIBUTING.md#a-typical-contributor-workflow)_
- [ ] 1. The issue provides a reproduction available on Github, Stackblitz or CodeSandbox
> Make sure to fork this template and run `yarn generate` in the terminal.
>
> Please make sure the GraphQL Tools package versions under `package.json` matches yours.
- [ ] 2. A failing test has been provided
- [ ] 3. A local solution has been provided
- [ ] 4. A pull request is pending review
---
**Describe the bug**
Multiple directives has been defined in apollo v4
`const directivesObj = {
isAuthenticated: authDirectiveTransformer,
hasRole: hasRoleDirectiveTransformer,
rateLimit: rateLimitDirectiveTransformer,
};`
`const applyDirective = schema => {
for (const directive in directivesObj) {
schema = directivesObj[directive](schema, directive);
}
return schema;
};`
`let schema = makeExecutableSchema({
typeDefs,
resolvers,
});`
`
schema = applyDirective(schema);
`
the directives are working in the sequence as mentioned in the `directivesObj` from bottom to top, not as they are defined in the graphql query. I have checked the apolloV4 documentation, but there is only a single directive example.
Need to know how the apolloV4 handles multiple directives to apply to single query.
**Expected behavior**
It should be worked dynamically applied to the graphql query not as defined in the schema object.
**Environment:**
- `@graphql-tools/...`:
- "@graphql-tools/load-files": "6.6.1",
"@graphql-tools/merge": "8.4.2",
"@graphql-tools/schema": "10.0.0",
"@graphql-tools/utils": "10.0.0",
- NodeJS: version 20.2.0
Contributor guide
Research direction
Start with the provided directivesObj and applyDirective example, using the listed @graphql-tools package versions and Node.js 20.2. Reproduce the ordering with a minimal schema and query; no repository file, failing test, or reproduction is supplied. Done means confirming the expected directive order and documenting or fixing the behavior with a failing test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- node.js, typescript
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100