gramps-graphql / gramps--legacy

The core data source combination engine of GrAMPS.

Home Page:https://gramps.js.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Create a plugin for the GraphQL CLI

jlengstorf opened this issue · comments

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.

For creating a datasource?

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

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 fsevents@1.1.2: The platform "win32" is incompatible with this module.
info "fsevents@1.1.2" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
warning " > @gramps/cli@1.0.0-beta.4" has unmet peer dependency "graphql@^0.11.7".
warning " > @gramps/gramps@1.0.0-beta-7" has unmet peer dependency "graphql@^0.9.0 || ^0.10.0 || ^0.11.0".
warning " > graphql-tools@2.13.0" has unmet peer dependency "graphql@^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0".
warning " > babel-jest@21.2.0" 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.

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.

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.

@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.

@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!