Skip to content

Commit

Permalink
skip scalars with required args for __scalar, really fix remorses#142
Browse files Browse the repository at this point in the history
  • Loading branch information
remorses committed Jan 18, 2024
1 parent c3879f9 commit f3515fe
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 3 deletions.
2 changes: 2 additions & 0 deletions architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,5 @@ type GetCountriesRequest<I, S> = {

function buildQuery()
```


1 change: 1 addition & 0 deletions cli/src/render/typeMap/renderTypeMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export const renderTypeMap = (schema: GraphQLSchema, ctx: RenderContext) => {
result.types[t.name] = objectType(t, ctx)
else if (isUnionType(t)) result.types[t.name] = unionType(t, ctx)
else if (isScalarType(t) || isEnumType(t)) {

result.scalars.push(t.name)
result.types[t.name] = {}
}
Expand Down
19 changes: 18 additions & 1 deletion cli/src/runtime/linkTypeMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,24 @@ export const linkTypeMap = (
// type scalar properties
scalar: Object.keys(fields).filter((f) => {
const [type] = fields[f] || []
return type && typeMap.scalars.includes(type)

const isScalar =
type && typeMap.scalars.includes(type)
if (!isScalar) {
return false
}
const args = fields[f]?.[1]
const argTypes = Object.values(args || {})
.map((x) => x?.[1])
.filter(Boolean)

const hasRequiredArgs = argTypes.some(
(str) => str && str.endsWith('!'),
)
if (hasRequiredArgs) {
return false
}
return true
}),
// fields with corresponding `type` and `args`
fields: Object.assign(
Expand Down
4 changes: 4 additions & 0 deletions integration-tests/__snapshots__/simple.ts.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ subscription SomeName {
fragment f1 on User {
name
common
commonButDiffType
__typename
}
Expand All @@ -109,6 +110,7 @@ subscription {
fragment f1 on User {
name
common
commonButDiffType
__typename
}
Expand Down Expand Up @@ -139,6 +141,7 @@ fragment f1 on Fork {
fragment f2 on User {
name
common
commonButDiffType
__typename
}
Expand All @@ -161,6 +164,7 @@ subscription {
}
fragment f1 on User {
name
commonButDiffType
__typename
}
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/tests/execution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,8 @@ describe('execute queries', async function () {
}),
)

it(
'union types, same field on multiple types',
it.skip(
'union types, same field on multiple types but different type',
withServer(async () => {
const { account } = await client.query({
account: {
Expand Down

0 comments on commit f3515fe

Please sign in to comment.