-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add support for better fragment type resolution
- Loading branch information
Showing
12 changed files
with
156 additions
and
21 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,25 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": "Dart: Run all Tests", | ||
"type": "dart", | ||
"request": "launch", | ||
"program": "./test/" | ||
}, | ||
{ | ||
"name": "Dart: Run Tests", | ||
"type": "dart", | ||
"request": "launch", | ||
"program": "./test/fragment_spread.dart" | ||
}, | ||
{ | ||
"name": "normalize", | ||
"request": "launch", | ||
"type": "dart" | ||
} | ||
] | ||
} |
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
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
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
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
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
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
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
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
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
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
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,95 @@ | ||
import 'package:test/test.dart'; | ||
import 'package:gql/language.dart'; | ||
|
||
import 'package:normalize/normalize.dart'; | ||
|
||
void main() { | ||
group('Normalizing and denormalizing fragments', () { | ||
test('Simple fragment', () { | ||
final possibleTypeOf = { | ||
'Author': {'User'}, | ||
'Audience': {'User'}, | ||
}; | ||
final document = parseString(''' | ||
fragment FAuthor on Author { | ||
__typename | ||
id | ||
} | ||
fragment FAudience on Audience { | ||
__typename | ||
id | ||
numHands | ||
isClapping | ||
} | ||
fragment FUser on User { | ||
id | ||
__typename | ||
name | ||
} | ||
query { | ||
users { | ||
...FAuthor | ||
...FAudience | ||
...FUser | ||
} | ||
} | ||
'''); | ||
final data = { | ||
'users': [ | ||
{'__typename': 'Author', 'id': '1', 'name': 'Knud'}, | ||
{ | ||
'__typename': 'Audience', | ||
'id': 'a', | ||
'name': 'Lars', | ||
'numHands': 2, | ||
'isClapping': false | ||
}, | ||
], | ||
}; | ||
|
||
final normalizedMap = { | ||
'Author:1': { | ||
'__typename': 'Author', | ||
'id': '1', | ||
'name': 'Knud', | ||
}, | ||
'Audience:a': { | ||
'__typename': 'Audience', | ||
'id': 'a', | ||
'numHands': 2, | ||
'isClapping': false, | ||
'name': 'Lars' | ||
}, | ||
'Query': { | ||
'users': [ | ||
{r'$ref': 'Author:1'}, | ||
{r'$ref': 'Audience:a'} | ||
] | ||
}, | ||
}; | ||
final normalizedResult = {}; | ||
normalizeOperation( | ||
read: (dataId) => normalizedResult[dataId], | ||
write: (dataId, value) => normalizedResult[dataId] = value, | ||
document: document, | ||
data: data, | ||
acceptPartialData: false, | ||
possibleTypeOf: possibleTypeOf, | ||
); | ||
expect( | ||
normalizedResult, | ||
equals(normalizedMap), | ||
); | ||
|
||
expect( | ||
denormalizeOperation( | ||
document: document, | ||
handleException: false, | ||
read: (dataId) => normalizedMap[dataId], | ||
possibleTypeOf: possibleTypeOf, | ||
), | ||
equals(data), | ||
); | ||
}); | ||
}); | ||
} |