Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
99980e0
commit f31186f
Showing
11 changed files
with
207 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
'use strict' | ||
|
||
const { getField, createQueryArguments, createUnionQuery, createQueryToTest } = require('./util') | ||
|
||
function create (schema, query, selectedQueries, args, isMutation) { | ||
if (selectedQueries.length) { | ||
const isQueryToTest = selectedQueries.indexOf(query.name) | ||
if (isQueryToTest < 0) return | ||
} | ||
|
||
let queryHeader | ||
if (query.arguments.length) { | ||
const createdArgs = createQueryArguments(query.arguments, args[query.name]) | ||
queryHeader = `${query.name}(${createdArgs})` | ||
} else { | ||
queryHeader = query.name | ||
} | ||
|
||
const queriesToTest = [] | ||
if (['ID', 'String', 'Int', 'Float', 'Boolean'].indexOf(query.type) >= 0) { | ||
const queryToTest = createQueryToTest([], queryHeader, isMutation) | ||
queriesToTest.push(queryToTest) | ||
return queriesToTest | ||
} | ||
|
||
const nestedType = schema[query.type] | ||
const fields = [] | ||
|
||
if (nestedType.type === 'UnionTypeDefinition') { | ||
const unionQueries = [] | ||
nestedType.types.forEach(type => { | ||
const newNestedType = schema[type] | ||
|
||
unionQueries.push(createUnionQuery(newNestedType, schema, type)) | ||
}) | ||
|
||
const queryToTest = createQueryToTest(unionQueries, queryHeader, isMutation) | ||
|
||
queriesToTest.push(queryToTest) | ||
} else { | ||
nestedType.fields.forEach(field => { | ||
const createdField = getField(field, schema) | ||
fields.push(createdField) | ||
|
||
const queryToTest = createQueryToTest(fields, queryHeader, isMutation) | ||
|
||
queriesToTest.push(queryToTest) | ||
}) | ||
} | ||
|
||
return queriesToTest | ||
} | ||
|
||
module.exports = create |
Oops, something went wrong.