GraphQL Array<T> vs T[] inconsistencies
Bug Report
Current Behavior
A read model that uses Array<T> can be queried via GraphQL, while a read model that uses (the semantically identical notation) T[] will throw the following GraphQL error JSONObject cannot represent non-object value
✅ this works
export class OrdersByOwner {
public constructor(
public id: UUID,
readonly orderIds: Array<UUID>
) {}
❌ this fails with above error when queried via GraphQL
export class OrdersByOwner {
public constructor(
public id: UUID,
readonly orderIds: UUID[]
) {}
Expected behavior
Both Array<T> and T[] to work and not throw any errors (I assume that in typescript both ways are semantically identical)
Additional information
Potentially related/similar issues: #338, #436
Environment
- Booster version:
@boostercloud/cli/0.24.2 darwin-x64 node-v14.18.1 ([email protected]) - OS: OSX 12.1
Checklist
- [X]
packages/framework-core/src/library/graphql-adapter.ts✅ Commit8394c32 - [X]
packages/framework-provider-aws/src/library/graphql-adapter.ts⚠️ No Changes Made - [X]
packages/framework-core/test/library/graphql-adapter.test.ts✅ Commitf77b15e - [X]
packages/framework-provider-aws/test/library/graphql-adapter.test.ts✅ Commit4fde026
Here's the PR! https://github.com/boostercloud/booster/pull/1471.
Actions (click)
- [ ] ↻ Restart Sweep
Step 1: 🔎 Searching
I found the following snippets in your repository. I will now analyze these snippets and come up with a plan.
Some code snippets I looked at (click to expand). If some file is missing from here, you can mention the path in the ticket description.
https://github.com/boostercloud/booster/blob/8c2328d75300c01a4487d4938a26072965481bb3/website/docs/03_architecture/06_read-model.mdx#L215-L325
https://github.com/boostercloud/booster/blob/8c2328d75300c01a4487d4938a26072965481bb3/packages/framework-integration-tests/integration/fixtures/read-models/cart-with-fields-read-model.ts#L1-L12
https://github.com/boostercloud/booster/blob/8c2328d75300c01a4487d4938a26072965481bb3/packages/framework-integration-tests/src/read-models/products-by-sku.ts#L1-L39
https://github.com/boostercloud/booster/blob/8c2328d75300c01a4487d4938a26072965481bb3/packages/framework-integration-tests/src/migrations/entities/Product/schema-versions.ts#L1-L17
https://github.com/boostercloud/booster/blob/8c2328d75300c01a4487d4938a26072965481bb3/packages/framework-integration-tests/integration/fixtures/read-models/cart-with-projection-read-model.ts#L1-L18
Step 2: ⌨️ Coding
- [X]
packages/framework-core/src/library/graphql-adapter.ts✅ Commit8394c32
Create packages/framework-core/src/library/graphql-adapter.ts with contents:
• Locate the function that is responsible for transforming the read model fields to GraphQL fields.
• Add a condition to check if the field type is an array using `T[]` notation.
• If the field type is an array using `T[]` notation, transform it to `Array` notation before processing it further.
- [X]
packages/framework-provider-aws/src/library/graphql-adapter.ts⚠️ No Changes Made
Modify packages/framework-provider-aws/src/library/graphql-adapter.ts with contents:
• Repeat the same steps as in `packages/framework-core/src/library/graphql-adapter.ts`.
- [X]
packages/framework-core/test/library/graphql-adapter.test.ts✅ Commitf77b15e
Create packages/framework-core/test/library/graphql-adapter.test.ts with contents:
• Create a new test file for `graphql-adapter.ts` if it does not exist.
• Add a test case to verify that the GraphQL adapter can handle read models with `T[]` notation correctly.
• The test case should define a read model with a field using `T[]` notation, pass it to the GraphQL adapter, and assert that no errors are thrown and the output is as expected.
- [X]
packages/framework-provider-aws/test/library/graphql-adapter.test.ts✅ Commit4fde026
Modify packages/framework-provider-aws/test/library/graphql-adapter.test.ts with contents:
• Repeat the same steps as in `packages/framework-core/test/library/graphql-adapter.test.ts`.
Step 3: 🔁 Code Review
I have finished reviewing the code for completeness. I did not find errors for sweep/fix-graphql-array-t-inconsistencies.
.
🎉 Latest improvements to Sweep:
- Sweep can now passively improve your repository! Check out Rules to learn more.
💡 To recreate the pull request edit the issue title or description. To tweak the pull request, leave a comment on the pull request. Join Our Discord