-
-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix dangling inline fragments when flattening fragments with unions (#…
…836) * fix dangling inline fragments when flattening fragments with unions * changeset
- Loading branch information
1 parent
44da563
commit 0f1f0b4
Showing
3 changed files
with
111 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'houdini': patch | ||
--- | ||
|
||
Fix syntax error when generating artifacts for queries that contain fragments with direct inline fragment children |
89 changes: 89 additions & 0 deletions
89
packages/houdini/src/codegen/generators/artifacts/selection.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import * as graphql from 'graphql' | ||
import { test, expect } from 'vitest' | ||
|
||
import { mockCollectedDoc, testConfig } from '../../../test' | ||
import { flattenSelections } from '../../utils' | ||
import selection from './selection' | ||
|
||
test('fragments of unions inject correctly', function () { | ||
const document = graphql.parse(` | ||
query { | ||
entities { | ||
...EntityInfo | ||
} | ||
} | ||
fragment EntityInfo on Entity { | ||
... on User { | ||
firstName | ||
} | ||
... on Cat { | ||
name | ||
} | ||
} | ||
`) | ||
|
||
const config = testConfig() | ||
const fragmentDefinitions = { | ||
EntityInfo: document.definitions.find( | ||
(def): def is graphql.FragmentDefinitionNode => def.kind === 'FragmentDefinition' | ||
)!, | ||
} | ||
|
||
const flat = flattenSelections({ | ||
config, | ||
filepath: '', | ||
selections: document.definitions.find( | ||
(def): def is graphql.OperationDefinitionNode => def.kind === 'OperationDefinition' | ||
)!.selectionSet.selections, | ||
fragmentDefinitions, | ||
ignoreMaskDisable: true, | ||
applyFragments: true, | ||
}) | ||
|
||
const artifactSelection = selection({ | ||
config, | ||
filepath: '', | ||
rootType: 'Query', | ||
operations: {}, | ||
selections: flat, | ||
includeFragments: false, | ||
document: mockCollectedDoc(` | ||
query Query { | ||
entities { | ||
...EntityInfo | ||
} | ||
}`), | ||
}) | ||
|
||
expect(artifactSelection).toMatchInlineSnapshot(` | ||
{ | ||
"fields": { | ||
"entities": { | ||
"type": "Entity", | ||
"keyRaw": "entities", | ||
"selection": { | ||
"abstractFields": { | ||
"fields": { | ||
"User": { | ||
"firstName": { | ||
"type": "String", | ||
"keyRaw": "firstName" | ||
} | ||
}, | ||
"Cat": { | ||
"name": { | ||
"type": "String", | ||
"keyRaw": "name" | ||
} | ||
} | ||
}, | ||
"typeMap": {} | ||
} | ||
}, | ||
"abstract": true | ||
} | ||
} | ||
} | ||
`) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters