Skip to content
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

babel-relay-plugin: output type name for non-scalar arguments #172

Merged
Merged
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: 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');
})();