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

Add allowFieldArgs #86

Merged
merged 1 commit into from
Sep 11, 2019
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
23 changes: 13 additions & 10 deletions generator/config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const { existsSync } = require("fs");
const { resolve } = require("path");
const cosmiconfig = require('cosmiconfig');
const { existsSync } = require("fs")
const { resolve } = require("path")
const cosmiconfig = require("cosmiconfig")

const explorer = cosmiconfig('mst-gql');
const explorer = cosmiconfig("mst-gql")

const defaultConfig = {
excludes: [],
Expand All @@ -13,15 +13,16 @@ const defaultConfig = {
outDir: "src/models",
roots: [],
noReact: false,
allowFieldArgs: false
}

exports.getConfig = function getConfig() {
try {
const result = explorer.searchSync();
return result ? result.config : defaultConfig;
const result = explorer.searchSync()
return result ? result.config : defaultConfig
} catch (e) {
console.error(e.message);
return defaultConfig;
console.error(e.message)
return defaultConfig
}
}

Expand All @@ -35,9 +36,10 @@ exports.mergeConfigs = function mergeConfigs(args, config) {
const excludes = args["--excludes"]
? args["--excludes"].split(",").map(s => s.trim())
: config.excludes
const modelsOnly =!!args["--modelsOnly"] || config.modelsOnly
const modelsOnly = !!args["--modelsOnly"] || config.modelsOnly
const forceAll = !!args["--force"] || config.force
const noReact = !!args["--noReact"] || config.noReact
const allowFieldArgs = !!args["--allowFieldArgs"] || config.allowFieldArgs

return {
format,
Expand All @@ -46,6 +48,7 @@ exports.mergeConfigs = function mergeConfigs(args, config) {
roots,
excludes,
modelsOnly,
forceAll
forceAll,
allowFieldArgs
}
}
5 changes: 3 additions & 2 deletions generator/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ function generate(
excludes = [],
generationDate = "a long long time ago...",
modelsOnly = false,
noReact = false
noReact = false,
allowFieldArgs = false
) {
excludes.push(...buildInExcludes)

Expand Down Expand Up @@ -294,7 +295,7 @@ ${generateFragments(name, primitiveFields, nonPrimitiveFields)}
let modelProperties = ""
if (type.fields) {
modelProperties = type.fields
.filter(field => field.args.length === 0)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious why this line was here in the first place (@mweststrate) but if things work fine without it I'm all for just removing it entirely vs. adding an allowFieldArgs option.

Copy link
Contributor

@scherler scherler Sep 2, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm yeah, I thought maybe originally it was meant as field.args.length !== 0 but does not make sense either down the line. I agree @chrisdrackett just drop only that line (would as well reduce all the unrelated formatting changes) :trollface:

.filter(field => (allowFieldArgs ? true : field.args.length === 0))
.map(field => handleField(field))
.join("\n")
}
Expand Down
20 changes: 16 additions & 4 deletions generator/mst-gql-scaffold.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const fs = require("fs")
const child_process = require("child_process")
const graphql = require("graphql")

const { getConfig, mergeConfigs } = require('./config');
const { getConfig, mergeConfigs } = require("./config")
const { generate, writeFiles } = require("./generate")

const definition = {
Expand All @@ -16,7 +16,8 @@ const definition = {
"--modelsOnly": Boolean,
"--force": Boolean,
"--noReact": Boolean,
"--separate": Boolean
"--separate": Boolean,
"--allowFieldArgs": Boolean
}

function main() {
Expand All @@ -33,7 +34,17 @@ function main() {
throw e
}

const { format, outDir, input, roots, excludes, modelsOnly, forceAll, noReact } = mergeConfigs(args, config);
const {
format,
outDir,
input,
roots,
excludes,
modelsOnly,
forceAll,
noReact,
allowFieldArgs
} = mergeConfigs(args, config)
const separate = !!args["--separate"]

console.log(
Expand Down Expand Up @@ -93,7 +104,8 @@ function main() {
excludes,
new Date().toUTCString(),
modelsOnly,
noReact
noReact,
allowFieldArgs
)
writeFiles(outDir, files, format, forceAll, true, separate)
}
Expand Down