apollo-codegen
Advanced tools
Comparing version 0.6.0 to 0.7.0
@@ -148,4 +148,4 @@ #!/usr/bin/env node | ||
}).fail(function (message, error) { | ||
handleError(error ? error : new Error(message)); | ||
}).help().strict().argv; | ||
handleError(error ? error : new _errors.ToolError(message)); | ||
}).help().version().strict().argv; | ||
//# sourceMappingURL=cli.js.map |
@@ -159,2 +159,3 @@ 'use strict'; | ||
var operationName = operationDefinition.name.value; | ||
var operationType = operationDefinition.operation; | ||
@@ -183,3 +184,3 @@ var variables = operationDefinition.variableDefinitions.map(function (node) { | ||
return { operationName: operationName, variables: variables, source: source, fields: fields, fragmentsReferenced: fragmentsReferenced }; | ||
return { operationName: operationName, operationType: operationType, variables: variables, source: source, fields: fields, fragmentsReferenced: fragmentsReferenced }; | ||
} | ||
@@ -186,0 +187,0 @@ }, { |
@@ -76,2 +76,3 @@ 'use strict'; | ||
var operationName = _ref.operationName; | ||
var operationType = _ref.operationType; | ||
var variables = _ref.variables; | ||
@@ -82,8 +83,23 @@ var fields = _ref.fields; | ||
var className = (0, _changeCase.pascalCase)(operationName) + 'Query'; | ||
var className = void 0; | ||
var protocol = void 0; | ||
switch (operationType) { | ||
case 'query': | ||
className = (0, _changeCase.pascalCase)(operationName) + 'Query'; | ||
protocol = 'GraphQLQuery'; | ||
break; | ||
case 'mutation': | ||
className = (0, _changeCase.pascalCase)(operationName) + 'Mutation'; | ||
protocol = 'GraphQLMutation'; | ||
break; | ||
default: | ||
throw new _graphql.GraphQLError('Unsupported operation type "' + operationType + '"'); | ||
} | ||
(0, _language.classDeclaration)(generator, { | ||
className: className, | ||
modifiers: ['public', 'final'], | ||
adoptedProtocols: ['GraphQLQuery'] | ||
adoptedProtocols: [protocol] | ||
}, function () { | ||
@@ -90,0 +106,0 @@ if (source) { |
{ | ||
"name": "apollo-codegen", | ||
"version": "0.6.0", | ||
"version": "0.7.0", | ||
"description": "Generate client code based on a GraphQL schema and query documents", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
@@ -36,2 +36,3 @@ import chai, { expect } from 'chai' | ||
operationName: 'HeroName', | ||
operationType: 'query', | ||
variables: [ | ||
@@ -93,2 +94,3 @@ { name: 'episode', type: 'Episode' } | ||
operationName: 'Hero', | ||
operationType: 'query', | ||
variables: [], | ||
@@ -146,2 +148,3 @@ fragmentsReferenced: [], | ||
operationName: 'Hero', | ||
operationType: 'query', | ||
variables: [], | ||
@@ -223,2 +226,3 @@ fragmentsReferenced: ['HeroDetails', 'MoreHeroDetails'], | ||
operationName: 'HeroAndFriends', | ||
operationType: 'query', | ||
variables: [], | ||
@@ -294,2 +298,3 @@ fragmentsReferenced: ['HeroDetails'], | ||
operationName: 'Hero', | ||
operationType: 'query', | ||
variables: [], | ||
@@ -366,2 +371,3 @@ fragmentsReferenced: [], | ||
operationName: 'Hero', | ||
operationType: 'query', | ||
variables: [], | ||
@@ -430,2 +436,3 @@ fragmentsReferenced: ['DroidDetails', 'HumanDetails'], | ||
operationName: 'Hero', | ||
operationType: 'query', | ||
variables: [], | ||
@@ -473,2 +480,3 @@ fragmentsReferenced: ['HeroDetails'], | ||
operationName: 'Hero', | ||
operationType: 'query', | ||
variables: [], | ||
@@ -547,2 +555,3 @@ fragmentsReferenced: ['HeroDetails'], | ||
operationName: 'HeroName', | ||
operationType: 'query', | ||
variables: [], | ||
@@ -590,2 +599,3 @@ fragmentsReferenced: [], | ||
operationName: 'HeroName', | ||
operationType: 'query', | ||
variables: [], | ||
@@ -635,2 +645,3 @@ fragmentsReferenced: [], | ||
operationName: 'HeroName', | ||
operationType: 'query', | ||
variables: [], | ||
@@ -675,2 +686,3 @@ fragmentsReferenced: ['HeroName'], | ||
operationName: 'HeroName', | ||
operationType: 'query', | ||
variables: [], | ||
@@ -710,2 +722,3 @@ fragmentsReferenced: ['DroidName'], | ||
operationName: 'Search', | ||
operationType: 'query', | ||
variables: [], | ||
@@ -837,2 +850,33 @@ fragmentsReferenced: [], | ||
}); | ||
it(`should include the operationType for a query`, () => { | ||
const source = stripIndent` | ||
query HeroName { | ||
hero { | ||
name | ||
} | ||
} | ||
` | ||
const document = parse(source); | ||
const { operations } = compileToIR(schema, document); | ||
expect(operations['HeroName'].operationType).to.equal('query'); | ||
}); | ||
it(`should include the operationType for a mutation`, () => { | ||
const source = stripIndent` | ||
mutation CreateReview { | ||
createReview { | ||
stars | ||
commentary | ||
} | ||
} | ||
` | ||
const document = parse(source); | ||
const { operations } = compileToIR(schema, document); | ||
expect(operations['CreateReview'].operationType).to.equal('mutation'); | ||
}); | ||
}); | ||
@@ -839,0 +883,0 @@ |
@@ -264,2 +264,36 @@ import { expect } from 'chai'; | ||
}); | ||
it(`should generate a class declaration for a mutation with variables`, function() { | ||
const { operations } = this.compileFromSource(` | ||
mutation CreateReview($episode: Episode) { | ||
createReview(episode: $episode, review: { stars: 5, commentary: "Wow!" }) { | ||
stars | ||
commentary | ||
} | ||
} | ||
`); | ||
classDeclarationForOperation(this.generator, operations['CreateReview']); | ||
expect(this.generator.output).to.include(stripIndent` | ||
public final class CreateReviewMutation: GraphQLMutation { | ||
public static let operationDefinition = | ||
"mutation CreateReview($episode: Episode) {" + | ||
" createReview(episode: $episode, review: {stars: 5, commentary: \\"Wow!\\"}) {" + | ||
" stars" + | ||
" commentary" + | ||
" }" + | ||
"}" | ||
public let episode: Episode? | ||
public init(episode: Episode? = nil) { | ||
self.episode = episode | ||
} | ||
public var variables: GraphQLMap? { | ||
return ["episode": episode] | ||
} | ||
`); | ||
}); | ||
}); | ||
@@ -266,0 +300,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
251905
4897