Skip to content

Commit 9745846

Browse files
committed
Merge branch 'master' of github.com:graphql/graphql-js
2 parents b092215 + 500f85e commit 9745846

File tree

3 files changed

+33
-7
lines changed

3 files changed

+33
-7
lines changed

src/tools/print-schema/src/index.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@
77
* of patent rights can be found in the PATENTS file in the same directory.
88
*/
99

10-
import { getIntrospectionResult }
11-
from '../../../language/schema/printer';
10+
import { parseSchemaIntoAST }
11+
from '../../../language/schema/';
12+
import { buildASTSchema, introspectionQuery }
13+
from '../../../utilities/';
14+
import { graphql }
15+
from '../../../';
1216

1317
var Promise = require('bluebird');
1418
var parseArgs = require('minimist');
@@ -38,7 +42,9 @@ export async function executeTool() {
3842
}
3943

4044
var body = await fs.readFileAsync(argDict.file, 'utf8');
41-
var result = await getIntrospectionResult(body, argDict.query);
45+
var ast = parseSchemaIntoAST(body);
46+
var astSchema = buildASTSchema(ast, argDict.query, argDict.mutation);
47+
var result = await graphql(astSchema, introspectionQuery);
4248
var out = await JSON.stringify(result, null, 2);
4349
console.log(out);
4450
} catch (error) {
@@ -54,4 +60,8 @@ introspection query result from querying that schema.
5460
Required:
5561
5662
--file <path>: The path to the input schema definition file.
57-
--query <queryType>: The query type (root type) of the schema.`;
63+
--query <queryType>: The query type (root type) of the schema.
64+
65+
Optional:
66+
67+
--mutation <mutationType>: The mutation type (root type) of the schema.`;

src/utilities/__tests__/buildASTSchema.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ import { buildASTSchema } from '../buildASTSchema';
2020
* into an in-memory GraphQLSchema, and then finally
2121
* printing that GraphQL into the DSL
2222
*/
23-
function cycleOutput(body, queryType) {
23+
function cycleOutput(body, queryType, mutationType) {
2424
var ast = parseSchemaIntoAST(body);
25-
var schema = buildASTSchema(ast, queryType);
25+
var schema = buildASTSchema(ast, queryType, mutationType);
2626
return '\n' + printSchema(schema);
2727
}
2828

@@ -231,6 +231,22 @@ type Hello {
231231
var output = cycleOutput(body, 'Hello');
232232
expect(output).to.equal(body);
233233
});
234+
235+
it('Simple type with mutation', () => {
236+
var body = `
237+
type HelloScalars {
238+
str: String
239+
int: Int
240+
bool: Boolean
241+
}
242+
243+
type Mutation {
244+
addHelloScalars(str: String, int: Int, bool: Boolean): HelloScalars
245+
}
246+
`;
247+
var output = cycleOutput(body, 'HelloScalars', 'Mutation');
248+
expect(output).to.equal(body);
249+
});
234250
});
235251

236252
describe('Schema Parser Failures', () => {

src/utilities/buildASTSchema.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ export function buildASTSchema(
151151
schema = new GraphQLSchema({query: queryType});
152152
} else {
153153
schema = new GraphQLSchema({
154-
query: queryTypeName,
154+
query: queryType,
155155
mutation: produceTypeDef(astMap[mutationTypeName]),
156156
});
157157
}

0 commit comments

Comments
 (0)