ardatan / ardatan/graphql-mesh

Schema validation fails for JSON schema handlers

Open
#8,652 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
3.5k
Forks
363
Avg merge
6h 10m
Merged PRs (30d)
19

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](https://github.com/ardatan/graphql-mesh/tree/master/examples/hello-world),
[Stackblitz](https://stackblitz.com/github/ardatan/graphql-mesh/tree/master/examples/hello-world)
or
[CodeSandbox](https://codesandbox.io/s/github/ardatan/graphql-mesh/tree/master/examples/hello-world)

> Make sure to fork this template and run `yarn generate` in the terminal.
>
> Please make sure Mesh package versions under `package.json` matches yours.

- [ ] 2. A failing test has been provided
- [x] 3. A local solution has been provided
- [ ] 4. A pull request is pending review

---

**Describe the bug**

When running `yarn run mesh validate` for a mesh containing a handler for a JSON schema the validation fails with the following error:

```
ERROR [source=Hello World] Failed to generate the schema for the source
Validation failed for "schemaWithAnnotations" under ".mesh/sources/Hello World": undefined
```

**To Reproduce**

Steps to reproduce the behavior:

- https://codesandbox.io/s/github/ardatan/graphql-mesh/tree/master/examples/hello-world
- Run `yarn run mesh validate`

**Expected behavior**

The validation should be successful.

**Additional context**

After some additional digging I could trace down the actual error to be thrown by the [validate function](https://github.com/ardatan/graphql-mesh/blob/master/packages/legacy/store/src/index.ts#L168) to be
`[ "Directive 'transport' was removed from schema 'Query'" ]`.

It seems the structural representation of the transport directive differs between the two schemas compared during validation:

`oldSchema`:
```
"extensions": {},
"astNode": {
"directives": [
{
"kind": "Directive",
"name": { "kind": "Name", "value": "transport" },
"arguments": [
{
"kind": "Argument",
"name": { "kind": "Name", "value": "subgraph" },
"value": { "kind": "StringValue", "value": "Hello World" }
},
{
"kind": "Argument",
"name": { "kind": "Name", "value": "kind" },
"value": { "kind": "StringValue", "value": "rest" }
}
]
}
]
},
// ...
```

`newSchema`:
```
"extensions": {
"directives": {
"transport": { "subgraph": "Hello World", "kind": "rest" }
}
},
// ...
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the hello-world example and run `yarn run mesh validate` to reproduce the failure. Read `packages/legacy/store/src/index.ts`, especially the `validate` function, and compare how the transport directive is represented in the old and new schemas; done means JSON schema handler validation succeeds without the reported error.

Written by the indexing model from the issue text.

Assessment

Tech stack
json, typescript
Domain
api, backend, testing
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.