Skip to content

Commit

Permalink
babel plugin: print list/non-null annotations on variable types
Browse files Browse the repository at this point in the history
Summary: Addresses #203 - `printRelayQuery` does not inline complex argument values, instead it synthesizes new query arguments and sends the data as variables. This was failing for non-null or list types - fixed!
Closes #291

Reviewed By: @wincent

Differential Revision: D2431632
  • Loading branch information
josephsavona authored and facebook-github-bot-7 committed Sep 10, 2015
1 parent 2f1e287 commit 23696f2
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
13 changes: 7 additions & 6 deletions scripts/babel-relay-plugin/src/GraphQLPrinter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"use strict";

var kinds = require('graphql/language/kinds');
var printer = require('graphql/language/printer');
var types = require('graphql/type');
var typeIntrospection = require('graphql/type/introspection');

Expand Down Expand Up @@ -577,16 +578,16 @@ function getScalarValue(node) {
}

function getTypeForMetadata(type) {
type = types.getNamedType(type);
var namedType = types.getNamedType(type);
if (
type instanceof types.GraphQLEnumType ||
type instanceof types.GraphQLInputObjectType
namedType instanceof types.GraphQLEnumType ||
namedType instanceof types.GraphQLInputObjectType
) {
return type.name;
} else if (type instanceof types.GraphQLScalarType) {
return String(type);
} else if (namedType instanceof types.GraphQLScalarType) {
return null;
}
throw new Error('Unsupported call value type ' + type.name);
throw new Error('Unsupported call value type ' + namedType.name);
}

function isEnum(type) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ var q = (function () {
'parentType': 'SearchResult'
})], null, {
'rootArg': 'query',
'rootCallType': 'SearchInput'
'rootCallType': '[SearchInput!]'
}, 'QueryWithObjectArgument');
})();
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ type Root {
nodes(ids: [Int]): [Node]
media(id: Int): Media
viewer: Viewer
search(query: SearchInput): [SearchResult]
search(query: [SearchInput!]): [SearchResult]
}

type SearchResult {
Expand Down
14 changes: 11 additions & 3 deletions scripts/babel-relay-plugin/src/__tests__/testschema.rfc.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,17 @@
"name": "query",
"description": null,
"type": {
"kind": "INPUT_OBJECT",
"name": "SearchInput",
"ofType": null
"kind": "LIST",
"name": null,
"ofType": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "INPUT_OBJECT",
"name": "SearchInput",
"ofType": null
}
}
},
"defaultValue": null
}
Expand Down

0 comments on commit 23696f2

Please sign in to comment.