Skip to content
This repository has been archived by the owner on Sep 11, 2019. It is now read-only.

Create a plugin for the GraphQL CLI #64

Open
jlengstorf opened this issue Dec 22, 2017 · 7 comments
Open

Create a plugin for the GraphQL CLI #64

jlengstorf opened this issue Dec 22, 2017 · 7 comments

Comments

@jlengstorf
Copy link
Member

jlengstorf commented Dec 22, 2017

Let's add a graphql-cli plugin to allow for:

  • using the gramps CLI commands as part of the graphql suite of commands (e.g. graphql gramps dev --gateway ./my-gateway.js)
  • creating a new data source from gramps-graphql/data-source-base

Once we have some boilerplates ready, let's also expand this to allow creating a gateway.

@kbrandwijk
Copy link
Member

For creating a datasource?

@jlengstorf
Copy link
Member Author

@kbrandwijk That + using the gramps commands as part of the GraphQL CLI. I just updated the issue description to reflect goals.

@kbrandwijk
Copy link
Member

Tip: your datasource boilerplate already works with graphql create. You could throw an install.js in there, with some replace instructions (for package.json), but even without, it works fine:

λ graphql create my-datasource -b https://github.com/gramps-graphql/data-source-base
[graphql create] Downloading boilerplate from https://github.com/gramps-graphql/data-source-base/archive/master.zip...
[graphql create] Installing node dependencies for C:\Users\User\Development\gramps\server\my-datasource\package.json...
yarn install v1.3.2
warning ..\package.json: No license field
[1/4] Resolving packages...
[2/4] Fetching packages...
info [email protected]: The platform "win32" is incompatible with this module.
info "[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
warning " > @gramps/[email protected]" has unmet peer dependency "graphql@^0.11.7".
warning " > @gramps/[email protected]" has unmet peer dependency "graphql@^0.9.0 || ^0.10.0 || ^0.11.0".
warning " > [email protected]" has unmet peer dependency "graphql@^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0".
warning " > [email protected]" has unmet peer dependency "babel-core@^6.0.0 || ^7.0.0-alpha || ^7.0.0-beta || ^7.0.0".
[4/4] Building fresh packages...
success Saved lockfile.
Done in 106.64s.

@kbrandwijk
Copy link
Member

kbrandwijk commented Dec 23, 2017

Let's think about how a datasource could be stored in .graphqlconfig.yml. I think it should be added as a project, with a possible extensions object, but I don't know what settings it should contain:

projects:
  xckd: # this is the gramps datasource namespace
    schemaPath: 'schema.graphql'
    extensions:
      gramps:
        package: '@gramps/data-source-xckd' #or:
        local: './datasources/xckd'

Update: see my comment below for the reasons why this structure will not work.

@kbrandwijk
Copy link
Member

kbrandwijk commented Dec 23, 2017

Alternatively, there could be a single gramps project, and the different datasources can be put under extensions. The benefit of that is that the final schema file would go under schemaPath, and can be used for binding generation. This would require running gramps() from the CLI when adding a data source, to regenerate the schema.graphql file.
The big benefit of this comes when following the current best practices for the gateway: you create a schema, and you import the types you need from the remote schemas (for which you need a .graphql file). This is currently impossible.

@kbrandwijk
Copy link
Member

kbrandwijk commented Dec 25, 2017

@jlengstorf As it's Christmas 🎄, I created you a little Christmas present 🎁. As it turns out, both graphql-cli and gramps-cli use yargs, so adding the gramps-cli commands to graphql-cli required zero additional work. I created https://github.com/supergraphql/graphql-cli-gramps for you. I'd like you to check it out, after which I would be more than willing to transfer ownership of the repo to you. 🎅

Anything that requires additional integration with graphql-cli and its config can be added at a later stage, but at least your gramps dev command is now available via graphql gramps dev as well, which seems like a good first start.

@jlengstorf
Copy link
Member Author

@kbrandwijk This is amazing! I'm still mostly off the computer for holiday things, but I will dig into this and start playing over the next week or so. Thanks so much for putting this together!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants