Skip to content

Fixes Encoded JSON Result Ordering #94

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ Looking for help? Find resources [from the community](http://graphql.org/communi

This repo only contains the core GraphQL implementation. For a better experience when creating your GraphQL schema use [Graphiti](https://github.com/GraphQLSwift/Graphiti).

## Encoding Results

If you encode a `GraphQLResult` with an ordinary `JSONEncoder`, there are no guarantees that the field order will match the query,
violating the [GraphQL spec](https://spec.graphql.org/June2018/#sec-Serialized-Map-Ordering). To preserve this order, `GraphQLResult`
should be encoded using the `GraphQLJSONEncoder` provided by this package.

## Contributing

Most of this repo mirrors the structure of the canonical GraphQL implementation written in Javascript/Typescript. If there is any feature missing, looking at the original code and "translating" it to Swift works, most of the time. For example:
Expand Down
3 changes: 1 addition & 2 deletions Sources/GraphQL/GraphQL.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import Foundation
import NIO

public struct GraphQLResult : Equatable, Codable, CustomStringConvertible {
Expand Down Expand Up @@ -34,7 +33,7 @@ public struct GraphQLResult : Equatable, Codable, CustomStringConvertible {
}

public var description: String {
let data = try! JSONEncoder().encode(self)
let data = try! GraphQLJSONEncoder().encode(self)
return String(data: data, encoding: .utf8)!
}
}
Expand Down
Loading