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

Force plugins to be explicitely enabled #503

Closed
Weakky opened this issue Mar 17, 2020 · 5 comments
Closed

Force plugins to be explicitely enabled #503

Weakky opened this issue Mar 17, 2020 · 5 comments
Labels
needs/discussion Open-ended conversation about something (ideation, design, analysis, ...) scope/plugins type/feat Add a new capability or enhance an existing one

Comments

@Weakky
Copy link
Collaborator

Weakky commented Mar 17, 2020

Description

Right now, plugins are enabled by default as soon as they're in the dependencies of the package.json.

We should investigate ways to enable them only if they were explicitely enabled in some configs somewhere.

Notes

  • We probably need some config files to handle this. Right now, the config is handled as an API, which would force the CLI to always run the whole app to get the config. Separating the config into a "standalone" config file (eg: nexus.config.ts) would make reading the config much easier/faster/safer
@Weakky Weakky added type/feat Add a new capability or enhance an existing one scope/plugins labels Mar 17, 2020
@jasonkuhrt jasonkuhrt added the needs/discussion Open-ended conversation about something (ideation, design, analysis, ...) label Mar 17, 2020
@Weakky
Copy link
Collaborator Author

Weakky commented Mar 18, 2020

Update

After discussing that topic with @jasonkuhrt, we ended up with the following API:

Enable nexus-prisma-plugin

import { plugins } from 'nexus-future'
import nexusPluginPrisma from 'nexus-plugin-prisma'

plugins.use(nexusPluginPrisma({ /* optional configuration */ }))

Enable Nexus Schema built-in plugins

import { plugins } from 'nexus-future'

plugins.use(plugins.builtins.nullabilityGuard, ...)

Local plugin:

import { plugins } from 'nexus-future'

plugins.use((p) => {
 /* ... */
})

This API has several benefits:

  • It makes it possible to configure plugins
  • Plugins are no longer identified by their names. Therefore, it's now possible to add nexus built-ins plugins (null and authorize plugins). It's also possible for the user to create its own plugin locally without having to publish one
  • Furthermore, it would allow for our core to abstract some of its part as plugins. One example is server.custom(). We want for the plugins to be able to contribute custom servers (eg: nexus-plugin-apollo-server). If plugins are able to contribute custom servers, server.custom could simply become a nice abstraction over the creation of a plugin to contribute a custom server.

Notes

  • If we ever want to bring back implicit opt-in, they we should continue to force plugin packages to default export their plugin. If not, then plugins should now be able to export plugins however they want. eg: import { nexusPluginPrisma } from 'nexus-plugin-prisma'

@jasonkuhrt
Copy link
Member

jasonkuhrt commented Mar 18, 2020

@Weakky Thanks for capturing these notes. I still have reservations about the functional things we would be losing. I'll try to write them up soon. Maybe some of the losses can be recouped. I'm not sure this API actually has all the touted benefits we think. There is a subjective argument to be sure, but I want to partition the objective from subjective so we can better appraise the tradeoffs.

@jasonkuhrt
Copy link
Member

#514

@jasonkuhrt
Copy link
Member

Enable Nexus Schema built-in plugins

But for that, I think we should:

settings.change({
  schema: {
    // options here for builtin schema component plugins
    // user does not even know they are builtin schema component plugins
  }
})

We have an existing system. If we think it's good, and we think a schema plugin is good enough to bundle, then I think we should merge them.

@jasonkuhrt
Copy link
Member

Resolved by graphql-nexus/nexus@b0704dc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs/discussion Open-ended conversation about something (ideation, design, analysis, ...) scope/plugins type/feat Add a new capability or enhance an existing one
Projects
None yet
Development

No branches or pull requests

2 participants