hasura / hasura/graphql-engine

GraphQL field ordering is not respected in REST endpoint OpenAPI schema

Open
#8,090 0 comments 0 reactions 0 assignees View on GitHub
a/api/rest k/bug
Dominant language
TypeScript
Stars
32.1k
Forks
3k
PR merge metrics
PR metrics pending

Description

### Version Information

Server Version: v2.1.1

### Environment

OSS

### What is the expected behaviour?
The order of the properties in the OpenAPI schema should match the order they are defined in the GraphQL query.

### Keywords

Swagger, OpenAPI, GraphQL, REST Endpoint, Ordering

### What is the current behaviour?
The fields are presented out of order sometimes, but not always.

### How to reproduce the issue?
If I define a REST endpoint with the following GraphQL query:

```graphql
query MyQuery {
User {
first_name
last_name
handle
}
}
```

I get an OpenAPI/Swagger schema for that endpoint with properties in the incorrect order (`handle` is second, not third):

```json
"items": {
"type": "object",
"properties": {
"first_name": {
"title": "String",
"type": "string"
},
"handle": {
"title": "String",
"type": "string"
},
"last_name": {
"title": "String",
"type": "string"
}
}
},
```

### Can you identify the location in the source code where the problem exists?

I suspect the mis-ordering is happening at JSON encoding time, because the order of the properties inside the Schema is correct when it is created in `Hasura.Server.OpenAPI.declareOpenApiSpec`. However, a cursory look over the JSON encoding logic seems like it _ought_ to work correctly. There is something subtle going on here.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.