graphql-auto-query
Advanced tools
Comparing version 0.0.2 to 0.0.3
@@ -45,3 +45,3 @@ #!/usr/bin/env node | ||
const schema = await readSchema(url); | ||
const text = await (0, __1.generate)(schema, depth); | ||
const text = (0, __1.generate)(schema, depth); | ||
if (output) { | ||
@@ -48,0 +48,0 @@ fs_1.promises.writeFile(output, text); |
@@ -44,2 +44,11 @@ "use strict"; | ||
} | ||
generateArgsName(target, name) { | ||
const values = new Set(Object.keys(target)); | ||
const baseName = lowercaseFirst(name); | ||
let genName = baseName; | ||
for (let count = 1; values.has(genName); count++) { | ||
genName = `${baseName}${count <= 1 ? "" : count}`; | ||
} | ||
return genName; | ||
} | ||
createOutputFields(field, argsMap, maxLevel, level = 0) { | ||
@@ -62,3 +71,3 @@ if (level > maxLevel) | ||
: arg.name; | ||
const genName = this.generateName(argsMap, argName, false); | ||
const genName = this.generateArgsName(argsMap, argName); | ||
argsMap[genName] = arg.type.toString(); | ||
@@ -88,7 +97,5 @@ return `${createSpaces((level + 2) * 2)}${arg.name}: $${genName}`; | ||
} | ||
generateName(target, name, types) { | ||
generateFragmentName(target, name) { | ||
const values = new Set(Object.values(target)); | ||
const typeNames = types | ||
? new Set(this.types.map((v) => v.name)) | ||
: undefined; | ||
const typeNames = new Set(this.types.map((v) => v.name)); | ||
let genName = lowercaseFirst(name); | ||
@@ -104,3 +111,3 @@ while (values.has(genName) || typeNames?.has(genName)) { | ||
.map((v) => { | ||
const name = this.generateName(this.fragments, v.name, true); | ||
const name = this.generateFragmentName(this.fragments, v.name); | ||
this.fragments[v.name] = name; | ||
@@ -107,0 +114,0 @@ return `fragment ${name} on ${v.name} ${this.createFragmentFields(v.getFields())}\n`; |
@@ -40,3 +40,3 @@ #!/usr/bin/env node | ||
const schema = await readSchema(url); | ||
const text = await generate(schema, depth); | ||
const text = generate(schema, depth); | ||
if (output) { | ||
@@ -43,0 +43,0 @@ fs.writeFile(output, text); |
@@ -41,2 +41,11 @@ import { buildSchema, GraphQLList, GraphQLNonNull, GraphQLObjectType, GraphQLSchema, Kind, } from "graphql"; | ||
} | ||
generateArgsName(target, name) { | ||
const values = new Set(Object.keys(target)); | ||
const baseName = lowercaseFirst(name); | ||
let genName = baseName; | ||
for (let count = 1; values.has(genName); count++) { | ||
genName = `${baseName}${count <= 1 ? "" : count}`; | ||
} | ||
return genName; | ||
} | ||
createOutputFields(field, argsMap, maxLevel, level = 0) { | ||
@@ -59,3 +68,3 @@ if (level > maxLevel) | ||
: arg.name; | ||
const genName = this.generateName(argsMap, argName, false); | ||
const genName = this.generateArgsName(argsMap, argName); | ||
argsMap[genName] = arg.type.toString(); | ||
@@ -85,7 +94,5 @@ return `${createSpaces((level + 2) * 2)}${arg.name}: $${genName}`; | ||
} | ||
generateName(target, name, types) { | ||
generateFragmentName(target, name) { | ||
const values = new Set(Object.values(target)); | ||
const typeNames = types | ||
? new Set(this.types.map((v) => v.name)) | ||
: undefined; | ||
const typeNames = new Set(this.types.map((v) => v.name)); | ||
let genName = lowercaseFirst(name); | ||
@@ -101,3 +108,3 @@ while (values.has(genName) || typeNames?.has(genName)) { | ||
.map((v) => { | ||
const name = this.generateName(this.fragments, v.name, true); | ||
const name = this.generateFragmentName(this.fragments, v.name); | ||
this.fragments[v.name] = name; | ||
@@ -104,0 +111,0 @@ return `fragment ${name} on ${v.name} ${this.createFragmentFields(v.getFields())}\n`; |
{ | ||
"name": "graphql-auto-query", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"author": "SoraKumo <info@croud.jp>", | ||
@@ -9,3 +9,3 @@ "description": "Automatic generation of GraphQL queries from GraphQL schemas", | ||
"test": "ts-node src/command", | ||
"test:generate": "ts-node src/command test/source.graphql -o test/output.graphql" | ||
"test:generate": "ts-node src/command test/source.graphql -o test/output.graphql -d 5" | ||
}, | ||
@@ -12,0 +12,0 @@ "bin": { |
# graphql-auto-query | ||
Automatic generation of GraphQL queries from GraphQL schemas | ||
This project automatically generates GraphQL queries from GraphQL schemas. | ||
@@ -16,4 +16,5 @@ [schema.graphql](https://raw.githubusercontent.com/SoraKumo001/graphql-auto-query/master/test/source.graphql) -> [query.graphql](https://raw.githubusercontent.com/SoraKumo001/graphql-auto-query/master/test/output.graphql) | ||
### CLI | ||
```sh | ||
# Standard output from server | ||
@@ -29,3 +30,3 @@ graphql-auto-query http://localhost:3000/graphql | ||
## When used as a library | ||
## library | ||
@@ -32,0 +33,0 @@ ```ts |
19611
409
38