-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Fix issue with Relay serialization #2638
Changes from 1 commit
91e8043
7bb0b26
186d5ea
dea43d5
3c32028
a68d585
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,10 +79,10 @@ fragment UserFragment_mutated on User @argumentDefinitions( | |
... on Mutated @include(if: $cond_mutated) { | ||
id_mutated | ||
__typename_mutated | ||
checkins_mutated(environments_mutated: [WEB_mutated]) { | ||
checkins_mutated(environments_mutated: [MOBILE]) { | ||
__typename_mutated | ||
} | ||
friends_mutated(after_mutated: $after_mutated, first_mutated: $first_mutated, traits_mutated: [HELPFUL_mutated]) { | ||
friends_mutated(after_mutated: $after_mutated, first_mutated: $first_mutated, traits_mutated: [DERISIVE]) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's keep the original N/N_mutated style just to make it more obvious what the test is doing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can't, serialization for enums only returns valid values and HEPLFUL_mutated isn't a valid enum value for traits. |
||
count_mutated | ||
} | ||
... on Mutated @skip(if: $cond_mutated) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,37 @@ const RelayTestSchemaPath = require('./RelayTestSchemaPath'); | |
const fs = require('fs'); | ||
|
||
const {buildASTSchema, parse} = require('graphql'); | ||
const {SchemaComposer} = require('graphql-compose'); | ||
|
||
module.exports = buildASTSchema( | ||
parse(fs.readFileSync(RelayTestSchemaPath, 'utf8'), {assumeValid: true}), | ||
); | ||
function buildSchema() { | ||
// Compose upstream is going to add AST directives soon, making this simpler | ||
const composer = new SchemaComposer(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. graphql-js supports extending schemas, can we just use that? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you point me to that? extendSchema only support extending via AST. |
||
const initialSchema = buildASTSchema( | ||
parse(fs.readFileSync(RelayTestSchemaPath, 'utf8'), {assumeValid: true}), | ||
); | ||
|
||
Object.keys(initialSchema.getTypeMap()).forEach(typeName => { | ||
const type = initialSchema.getType(typeName); | ||
composer.add(type); | ||
}); | ||
|
||
const CropPositionETC = composer.getETC('CropPosition'); | ||
CropPositionETC.setFields({ | ||
TOP: {value: 1}, | ||
CENTER: {value: 2}, | ||
BOTTOM: {value: 3}, | ||
LEFT: {value: 4}, | ||
RIGHT: {value: 5}, | ||
}); | ||
const FileExtensionETC = composer.getETC('FileExtension'); | ||
FileExtensionETC.setFields({ | ||
JPG: {value: 'jpg'}, | ||
PNG: {value: 'png'}, | ||
}); | ||
|
||
return composer.buildSchema({ | ||
directives: initialSchema.getDirectives(), | ||
}); | ||
} | ||
|
||
module.exports = buildSchema(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
"dependencies": { | ||
"@babel/runtime": "^7.0.0", | ||
"fbjs": "^1.0.0", | ||
"graphql-compose": "^5.8.0", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same question, we should use the built-in mechanism to extend schemas. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's my "lodash" for GraphQL type system 😈 If not today then it will be used tomorrow. Just give me some time to make this lib popular and right solution for such kind of problems. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Which mechanism? extendSchema only supports extending through AST. |
||
"iterall": "^1.2.1", | ||
"prop-types": "^15.5.8", | ||
"relay-compiler": "2.0.0", | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't remember if GraphQLInputObject and GraphQLList also support
serialize()
, if they do can we just use the approach here for all types (ie replace the body ofprintLiteral
w the body of the enum case)? Even if lists/objects don't work, we could do this for all enums and scalars.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only scalars and enums have serialize.