Skip to content
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

Comparing two GraphQLResult #160

Open
zamderax opened this issue Dec 13, 2024 · 0 comments
Open

Comparing two GraphQLResult #160

zamderax opened this issue Dec 13, 2024 · 0 comments

Comments

@zamderax
Copy link

zamderax commented Dec 13, 2024

Problem

Currently can't compare two GraphQLResult even though the data is the same.
I'm currently using swift-testing with Swift 6.0.2

let queryOrganizationBySlug: String = """
  query FindSingleOrganization($slug: String!) {
      findSingleOrganization(slug: $slug) {
        slug
        displayName
        details
        domain
      }
    }
"""
let variables: [String: Map] = ["slug": "acme-corp"]
let graphQLRequest = GraphQLRequest(query: query, variables: variables)
let encoder = GraphQLJSONEncoder()
    let buffer = ByteBuffer(data: try encoder.encode(graphQLRequest))
let response: GraphQLResult = try await client.runGraphQLQuery(
  url: "/graphql",
  buffer: buffer
)
let expected: GraphQLResult = GraphQLResult(
  data: [
    "findSingleOrganization": [
      "slug": "acme-corp",
      "displayName": "Acme Corporation",
      "details": "A leading technology company",
      "domain": "acme.com"
    ]
  ]
)
#expect(response == expected)

However I'm getting an issue on comparison even though GraphQLResult is Equatable. The error is as follows:

 Expectation failed: (response  {"data":{"findSingleOrganization":{"displayName":"Acme Corporation","details":"A leading technology company","domain":"acme.com","slug":"acme-corp"}}}) == (expected  {"data":{"findSingleOrganization":{"slug":"acme-corp","displayName":"Acme Corporation","details":"A leading technology company","domain":"acme.com"}}})

Which we can see that the data is the same, the only thing is that the data is in differing orders:

[
  {
    "data": {
      "findSingleOrganization": {
        "details": "A leading technology company",
        "domain": "acme.com",
        "slug": "acme-corp",
        "displayName": "Acme Corporation"
      }
    }
  },
  {
    "data": {
      "findSingleOrganization": {
        "slug": "acme-corp",
        "displayName": "Acme Corporation",
        "details": "A leading technology company",
        "domain": "acme.com"
      }
    }
  }
]

What's the proper way to compare the results?

In addition, I used

let graphQLRequest = GraphQLRequest(query: query, variables: variables)
let encoder = GraphQLJSONEncoder()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant