Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ npm-debug.log
/website/src/relay/docs
/website/src/relay/graphql
/website/src/relay/prototyping
.idea
.vscode
2 changes: 1 addition & 1 deletion scripts/babel-relay-plugin/lib/HASH
Original file line number Diff line number Diff line change
@@ -1 +1 @@
aLqnJZZNEJCxMT/D5cBKeOy9Bn4=
Wznuw5o6LskicwEjmBJp3XYD2no=
25 changes: 25 additions & 0 deletions scripts/babel-relay-plugin/lib/RelayQLAST.js
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,8 @@ var RelayQLArgument = (function () {
return value.values.map(function (value) {
return new RelayQLArgument(_this6.context, _extends({}, _this6.ast, { value: value }), _this6.type.ofType());
});
case 'ObjectValue':
return getInputObjectValue(value);
}
invariant(false, 'Unexpected argument kind: %s', value.kind);
}
Expand Down Expand Up @@ -817,6 +819,29 @@ function stripMarkerTypes(schemaModifiedType) {
return { isListType: isListType, isNonNullType: isNonNullType, schemaUnmodifiedType: schemaUnmodifiedType };
}

// unlike ListValue, ObjectValue return a
// plain javascript object(key-value)
function getInputObjectValue(inputObject) {
switch (inputObject.kind) {
case 'IntValue':
return parseInt(inputObject.value, 10);
case 'FloatValue':
return parseFloat(inputObject.value);
case 'StringValue':
case 'BooleanValue':
case 'EnumValue':
return inputObject.value;
case 'ListValue':
return inputObject.values.map(getInputObjectValue);
case 'ObjectValue':
var ob = {};
inputObject.fields.map(function (field) {
ob[field.name.value] = getInputObjectValue(field.value);
});
return ob;
}
}

module.exports = {
RelayQLArgument: RelayQLArgument,
RelayQLArgumentType: RelayQLArgumentType,
Expand Down
18 changes: 17 additions & 1 deletion scripts/babel-relay-plugin/lib/RelayQLPrinter.js
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ module.exports = function (t, options) {
}
return codify({
kind: t.valueToNode('CallValue'),
callValue: t.valueToNode(value)
callValue: printObject(value)
});
}
}, {
Expand Down Expand Up @@ -602,6 +602,22 @@ module.exports = function (t, options) {
}, null);
}

function printObject(jsValue) {
var keys = Object.keys(jsValue);
var jsType = typeof jsValue;
if (jsType == 'object' && keys.length > 0) {
if (Array.isArray(jsValue)) {
return t.arrayExpression(jsValue.map(printObject));
} else {
return t.objectExpression(keys.map(function (key) {
return property(key, printObject(jsValue[key]));
}));
}
} else {
return t.valueToNode(jsValue);
}
}

function objectify(obj) {
var properties = [];
Object.keys(obj).forEach(function (key) {
Expand Down
27 changes: 26 additions & 1 deletion scripts/babel-relay-plugin/src/RelayQLAST.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class RelayQLFragment extends RelayQLDefinition<

getFragmentID(): string {
if (this.fragmentID == null) {
let suffix = (_nextFragmentID++).toString(32);
const suffix = (_nextFragmentID++).toString(32);
// The fragmentLocationID is the same for all inline/nested fragments
// within each Relay.QL tagged template expression; the auto-incrementing
// suffix distinguishes these fragments from each other.
Expand Down Expand Up @@ -397,6 +397,8 @@ class RelayQLArgument {
this.type.ofType()
)
);
case 'ObjectValue':
return getInputObjectValue(value);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's move this to the bottom of the file to make it clear that it's a helper and doesn't rely on any scope here. also, how about naming it something like getInputObjectValue(inputObject) to make it more clear what it's doing?

invariant(false, 'Unexpected argument kind: %s', value.kind);
}
Expand Down Expand Up @@ -768,6 +770,29 @@ function stripMarkerTypes(schemaModifiedType: GraphQLSchemaType): {
return {isListType, isNonNullType, schemaUnmodifiedType};
}

// unlike ListValue, ObjectValue return a
// plain javascript object(key-value)
function getInputObjectValue(inputObject) {
switch (inputObject.kind) {
case 'IntValue':
return parseInt(inputObject.value, 10);
case 'FloatValue':
return parseFloat(inputObject.value);
case 'StringValue':
case 'BooleanValue':
case 'EnumValue':
return inputObject.value;
case 'ListValue':
return inputObject.values.map(getInputObjectValue);
case 'ObjectValue':
const ob={};
inputObject.fields.map(field => {
ob[field.name.value] = getInputObjectValue(field.value);
});
return ob;
}
}

module.exports = {
RelayQLArgument,
RelayQLArgumentType,
Expand Down
20 changes: 18 additions & 2 deletions scripts/babel-relay-plugin/src/RelayQLPrinter.js
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ module.exports = function(t: any, options: PrinterOptions): Function {
}
return codify({
kind: t.valueToNode('CallValue'),
callValue: t.valueToNode(value),
callValue: printObject(value),
});
}

Expand Down Expand Up @@ -780,7 +780,23 @@ module.exports = function(t: any, options: PrinterOptions): Function {
}, null);
}

function objectify(obj: {[key: string]: mixed}): Printable {
function printObject(jsValue: any):String {
var keys = Object.keys(jsValue);
var jsType = typeof jsValue;
if (jsType == 'object' && keys.length > 0) {
if (Array.isArray(jsValue)) {
return t.arrayExpression(jsValue.map(printObject));
}else {
return t.objectExpression(keys.map(key =>
property(key, printObject(jsValue[key]))
));
}
}else {
return t.valueToNode(jsValue);
}
}

function objectify(obj: any): Printable {
const properties = [];
Object.keys(obj).forEach(key => {
const value = obj[key];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@
{
"kind": "SCALAR",
"name": "Int",
"description": "The `Int` scalar type represents non-fractional signed whole numeric values. Int can represent values between -(2^53 - 1) and 2^53 - 1 since represented in JSON as double-precision floating point numbers specifiedby [IEEE 754](http://en.wikipedia.org/wiki/IEEE_floating_point).",
"description": "The `Int` scalar type represents non-fractional signed whole numeric values. Int can represent values between -(2^31) and 2^31 - 1. ",
"fields": null,
"inputFields": null,
"interfaces": null,
Expand Down
15 changes: 15 additions & 0 deletions scripts/jest/testschema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ type Root {
nodes(ids: [ID!]): [Node]
username(name: String!): Actor
usernames(names: [String!]!): [Actor]
fastestRoute(waypoints: [Waypoint!]!): Route
task(number: Int!): Task
viewer: Viewer
_mutation: Mutation
}
Expand Down Expand Up @@ -625,3 +627,16 @@ type Settings {
notificationSounds: Boolean
notifications(environment: Environment): Boolean
}

input Waypoint{
uri: String!
dumbNumber: [Int!]!
}

type Route{
dumb: String!
}

type Task{
dumb: String!
}
161 changes: 161 additions & 0 deletions scripts/jest/testschema.json
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,67 @@
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "fastestRoute",
"description": null,
"args": [
{
"name": "waypoints",
"description": null,
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "LIST",
"name": null,
"ofType": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "INPUT_OBJECT",
"name": "Waypoint"
}
}
}
},
"defaultValue": null
}
],
"type": {
"kind": "OBJECT",
"name": "Route",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "task",
"description": null,
"args": [
{
"name": "number",
"description": null,
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "Int",
"ofType": null
}
},
"defaultValue": null
}
],
"type": {
"kind": "OBJECT",
"name": "Task",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "viewer",
"description": null,
Expand Down Expand Up @@ -6737,6 +6798,106 @@
"enumValues": null,
"possibleTypes": null
},
{
"kind": "INPUT_OBJECT",
"name": "Waypoint",
"description": null,
"fields": null,
"inputFields": [
{
"name": "uri",
"description": null,
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "String",
"ofType": null
}
},
"defaultValue": null
},
{
"name": "dumbNumber",
"description": null,
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "LIST",
"name": null,
"ofType": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "Int"
}
}
}
},
"defaultValue": null
}
],
"interfaces": null,
"enumValues": null,
"possibleTypes": null
},
{
"kind": "OBJECT",
"name": "Route",
"description": null,
"fields": [
{
"name": "dumb",
"description": null,
"args": [],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "String",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
}
],
"inputFields": null,
"interfaces": [],
"enumValues": null,
"possibleTypes": null
},
{
"kind": "OBJECT",
"name": "Task",
"description": null,
"fields": [
{
"name": "dumb",
"description": null,
"args": [],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "String",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
}
],
"inputFields": null,
"interfaces": [],
"enumValues": null,
"possibleTypes": null
},
{
"kind": "OBJECT",
"name": "Viewer",
Expand Down
2 changes: 1 addition & 1 deletion src/interface/RelayOSSNodeInterface.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type PayloadResult = {

type RootCallInfo = {
storageKey: string;
identifyingArgValue: ?string;
identifyingArgValue: mixed;
}

/**
Expand Down
Loading