sezna / nps

NPM Package Scripts -- All the benefits of npm scripts without the cost of a bloated package.json and limits of json
MIT License
1.43k stars 93 forks source link

Options getting forwarded to graphql-cli cmd #169

Open donovanhiland opened 6 years ago

donovanhiland commented 6 years ago

Scripts file (or at least the relevant bits):

{
    scripts: {
        introspection: 'graphql get-schema'
    }
}

The command executed:

yarn start introspection

The output:

yarn run v1.3.2
$ nps introspection
nps is executing `introspection` : graphql get-schema
graphql get-schema

Download schema from endpoint

Options:
  --dotenv        Path to .env file                                     [string]
  -p, --project   Project name                                          [string]
  --watch, -w     watch server for schema changes and update local schema
                                                                       [boolean]
  --endpoint, -e  Endpoint name or URL                                  [string]
  --json, -j      Output as JSON                                       [boolean]
  --output, -o    Output file name                                      [string]
  --console, -c   Output to console                             [default: false]
  --insecure, -i  Allow insecure (self-signed) certificates            [boolean]
  --all           Get schema for all projects and all endpoints        [boolean]
  --header        Header to use for downloading (with endpoint URL)     [string]
  -h, --help      Show help                                            [boolean]
  -v, --version   Show version number                                  [boolean]

Unknown argument: endpointName
✨  Done in 1.47s.

Problem description:

When running graphql get-schema with nps, an endpointName options gets passed through which fails validation in graphql-cli. Running the same command from package.json scripts works as expected. I'm not sure where the issue can be resolved from, if either, so I think I'm going to open an issue in both and see if something can be resolved. Happy to help how I can.

kentcdodds commented 6 years ago

Huh... No idea why an endpointName would magically appear here. You could try diving into your node_modules to see if that helps...

Let us know what you come up with.

donovanhiland commented 6 years ago

Ok so the magically appearing endpointName isn't so magical after all. I have an env var GRAPHQL_CONFIG_ENDPOINT_NAME which yargs is parsing and passing as an argument with something like .env('GRAPHQL_CONFIG'). It's not expecting an endpointName argument and so fails on yargs.strict().

In my package.json:

{
  "scripts": {
    "start": "nps",
    "introspection": "graphql get-schema"
  }
}

My package-scripts.js

{
    scripts: {
        introspection: 'graphql get-schema',
        npmIntrospection: 'yarn run introspection'
    }
}

yarn start introspection - fails yarn start npmIntrospection - fails yarn run introspection - works

I'm curious as to why running it through nps in any fashion fails, but directly running the npm script works.

kentcdodds commented 6 years ago

I have no idea why this is happening though:

I have an env var GRAPHQL_CONFIG_ENDPOINT_NAME which yargs is parsing and passing as an argument with something like .env('GRAPHQL_CONFIG')

and

I'm curious as to why running it through nps in any fashion fails, but directly running the npm script works.

I'm also curious. I'm really sorry @donovanhiland, I just have very limited time to dedicate to this package so I can't be a lot of help to you here :-/

donovanhiland commented 6 years ago

I totally understand! I'll document any other findings here in case someone else runs into the same issue.

donovanhiland commented 6 years ago

Workaround: https://github.com/graphql-cli/graphql-cli/issues/228#issuecomment-369063177