Skip to content

Commit

Permalink
Merge pull request #172 from josephsavona/babel-plugin-argument-types
Browse files Browse the repository at this point in the history
babel-relay-plugin: output type name for non-scalar arguments
  • Loading branch information
josephsavona committed Aug 26, 2015
2 parents 61ddddb + f5c6ed0 commit aebacc8
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion scripts/babel-relay-plugin/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "babel-relay-plugin",
"version": "0.1.2",
"version": "0.1.3",
"description": "Babel Relay Plugin for transpiling GraphQL queries for use with Relay.",
"license": "BSD-3-Clause",
"repository": "facebook/relay",
Expand Down
15 changes: 8 additions & 7 deletions scripts/babel-relay-plugin/src/GraphQLPrinter.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ function printQuery(query, options) {
metadata.rootArg = rootCallDecl.args[0].name;

var rootCallTypeName = getTypeForMetadata(rootCallDecl.args[0].type);
if (rootCallTypeName !== 'scalar') {
if (rootCallTypeName) {
metadata.rootCallType = rootCallTypeName;
}
}
Expand Down Expand Up @@ -474,7 +474,7 @@ function printCalls(field, fieldDecl, options) {

var metadata = {};
var typeName = getTypeForMetadata(callDecl.type);
if (typeName !== 'scalar') {
if (typeName) {
metadata.type = typeName;
}
return (
Expand Down Expand Up @@ -537,12 +537,13 @@ function getScalarValue(node) {

function getTypeForMetadata(type) {
type = types.getNamedType(type);
if (type instanceof types.GraphQLEnumType) {
return 'enum';
} else if (type instanceof types.GraphQLInputObjectType) {
return 'object';
if (
type instanceof types.GraphQLEnumType ||
type instanceof types.GraphQLInputObjectType
) {
return type.name;
} else if (type instanceof types.GraphQLScalarType) {
return 'scalar';
return null;
}
throw new Error('Unsupported call value type ' + type.name);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ var foo = (function () {
"generated": true,
"requisite": true
})], null, [new GraphQL.Callv("first", 10), new GraphQL.Callv("orderby", "Name"), new GraphQL.Callv("find", "cursor1"), new GraphQL.Callv("isViewerFriend", true), new GraphQL.Callv("gender", "MALE", {
"type": "enum"
"type": "Gender"
})], null, null, {
"parentType": "Node",
"connection": true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ var x = (function () {
'generated': true,
'requisite': true
})], null, [new GraphQL.Callv('gender', 'MALE', {
'type': 'enum'
'type': 'Gender'
})], null, null, {
'parentType': 'Node',
'connection': true
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': 'object'
'rootCallType': 'SearchInput'
}, 'QueryWithObjectArgument');
})();

0 comments on commit aebacc8

Please sign in to comment.