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

Forward plugin fields in t.crud and t.model #584

Closed
gabrielcolson opened this issue Jan 27, 2020 · 11 comments · Fixed by #687
Closed

Forward plugin fields in t.crud and t.model #584

gabrielcolson opened this issue Jan 27, 2020 · 11 comments · Fixed by #687
Labels
effort/hard impact/high needs/investigation Possibly an issue, needs more analysis/research scope/architecture type/feat Add a new capability or enhance an existing one

Comments

@gabrielcolson
Copy link

Hey,

It would be nice to be able to access the "dynamic fields" created by the other plugins in t.model and t.crud.

Example with the Field Authorize Plugin:

makeSchema({
  // ...
  plugins: [fieldAuthorizePlugin(), nexusPrismaPlugin()],
  // ...
});

//...

t.model.email({
  authorize: (parent, args, ctx) => parent.id === ctx.userId,
});

t.crud.createOnePost({
  authorize: (parent, args, ctx) => isUserConntext(ctx),
});

I would be happy to contribute if you need me to. This is an important feature to me because I would like to get rid of Graphql Shield ASAP.

PS: I know there is an opened issue about the Field Authorize Plugin but I wanted to extend it to play nice with any other plugin.

@Weakky Weakky added type/feat Add a new capability or enhance an existing one impact/high needs/investigation Possibly an issue, needs more analysis/research effort/hard labels Jan 27, 2020
@Weakky Weakky added this to This Quarter in Labs Team Jan 27, 2020
@jasonkuhrt
Copy link
Member

jasonkuhrt commented Jan 27, 2020

Hey @gabrielcolson thanks for this idea. Looks good to us too. Bit of an experiment to see if this could lead to unintuitive fields on model/crud.

We’re not sure how hard this issue will be to implement but we would like to see it land this quarter. If by the end of February we think this might not make it from our side your contribution would be more than welcome.

@jcloutz-radix
Copy link

jcloutz-radix commented Mar 19, 2020

@jasonkuhrt was this issue removed from the This Quarter board in favor of something else, or is it just not a priority?

I'm not sure we really need to have the plugin attributes added to the generated type, though that would be nice. Personally i would settle for a the ability to pass an array of middleware that would wrap the generated resolver. Not having any ability to intercept the request is a massive pain point.

t.model.email({
  middleware: [(parent, args, ctx, info, next) => { /* continue or throw error */ }]
});

t.crud.createOnePost({
  middleware: [(parent, args, ctx, info, next) => { /* continue or throw error */ }]
});

@TLadd
Copy link

TLadd commented May 24, 2020

This is a big bummer at the moment. You basically have to choose between using nexus prisma or any other plugin (authorize, query complexity, custom ones, etc). A lot of the value in code-first schema construction are these plugins that allow abstracting common schema structure and functionality. The fact that the prisma plugin cuts you off from using the rest of them is really limiting.

@Weakky
Copy link
Member

Weakky commented Jun 5, 2020

Hey everyone, we've just made it possible to use external field plugins into Nexus Prisma thanks to #687. It'll be available in the next release of nexus-prisma.

@jcloutz-radix
Copy link

@Weakky this is great, thank you! Do you have an ETA on the release and what version it will be? This is directly impacting a project we have progress at the moment.

@jasonkuhrt
Copy link
Member

jasonkuhrt commented Jun 5, 2020

@jcloutz-radix canary today @next, stable in just under two weeks.

@Weakky
Copy link
Member

Weakky commented Jun 5, 2020

We've just released nexus-prisma@0.15.0-next.1.
You can try the feature by installing nexus-prisma@next right now. Feel free to report any bug related to it in here. I'll re-open the issue if needed 🙏

@jcloutz-radix
Copy link

@Weakky thank you!

I am trying to give it a test run using the blog example and it won't generate the nexus schema types.

When i downgrade to nexus-prisma@0.14.0-next.2 it generates without error.

/mnt/c/Users/jeremycloutier/develop/labs/nexus-schema-plugin-prisma/examples/blog/src/schema/Query.ts:5
    t.crud.blogs({
           ^
TypeError: Cannot read property 'blogs' of undefined
    at Object.definition (/mnt/c/Users/jeremycloutier/develop/labs/nexus-schema-plugin-prisma/examples/blog/src/schema/Query.ts:5:12)
    at SchemaBuilder.walkOutputType (/mnt/c/Users/jeremycloutier/develop/labs/nexus-schema-plugin-prisma/examples/blog/node_modules/@nexus/schema/src/builder.ts:1473:9)
    at SchemaBuilder.walkTypes (/mnt/c/Users/jeremycloutier/develop/labs/nexus-schema-plugin-prisma/examples/blog/node_modules/@nexus/schema/src/builder.ts:700:16)
    at SchemaBuilder.getFinalTypeMap (/mnt/c/Users/jeremycloutier/develop/labs/nexus-schema-plugin-prisma/examples/blog/node_modules/@nexus/schema/src/builder.ts:799:10)
    at makeSchemaInternal (/mnt/c/Users/jeremycloutier/develop/labs/nexus-schema-plugin-prisma/examples/blog/node_modules/@nexus/schema/src/builder.ts:1597:15)
    at Object.makeSchema (/mnt/c/Users/jeremycloutier/develop/labs/nexus-schema-plugin-prisma/examples/blog/node_modules/@nexus/schema/src/builder.ts:1642:49)
    at Object.<anonymous> (/mnt/c/Users/jeremycloutier/develop/labs/nexus-schema-plugin-prisma/examples/blog/src/schema/index.ts:12:28)
    at Module._compile (internal/modules/cjs/loader.js:816:30)
    at Module.m._compile (/mnt/c/Users/jeremycloutier/develop/labs/nexus-schema-plugin-prisma/examples/blog/node_modules/ts-node/src/index.ts:858:23)
    at Module._extensions..js (internal/modules/cjs/loader.js:827:10)

package.json

{
  "name": "example",
  "private": true,
  "version": "0.0.0",
  "main": "dist/main.ts",
  "scripts": {
    "clean": "rm -rf dist",
    "build": "yarn -s clean && yarn -s generate && tsc",
    "style": "prettier --write 'src/**/*'",
    "dev": "ts-node-dev --tree-kill --no-notify --respawn --transpile-only src/main.ts",
    "dev:migrate": "prisma2 migrate save --experimental -c && prisma2 migrate up --experimental -c",
    "generate": "yarn -s generate:prisma && yarn -s generate:nexus",
    "generate:prisma": "prisma generate",
    "generate:nexus": "NODE_ENV=development ts-node --transpile-only src/schema",
    "data:inject": "ts-node prisma/fake-data.ts"
  },
  "dependencies": {
    "@nexus/schema": "^0.14.0",
    "@prisma/client": "2.0.0-beta.8",
    "graphql": "^14.5.0",
    "graphql-yoga": "^1.18.2",
    "nexus-prisma": "^0.15.0-next.1"
  },
  "devDependencies": {
    "@prisma/cli": "2.0.0-beta.8",
    "@types/faker": "^4.1.12",
    "@types/ws": "^7.2.5",
    "faker": "^4.1.0",
    "prettier": "^2.0.5",
    "ts-node": "^8.10.2",
    "ts-node-dev": "^1.0.0-pre.41",
    "typescript": "^3.9.5"
  },
  "prettier": {
    "semi": false,
    "singleQuote": true,
    "trailingComma": "all"
  }
}

@Weakky
Copy link
Member

Weakky commented Jun 5, 2020

Sorry about that I forgot to update the examples.

Crud is now behind a feature flag.
Add experimentalCRUD: true to the plug-in constructor, that'll fix it

@jcloutz-radix
Copy link

@Weakky that did the trick!

@gustawdaniel
Copy link
Contributor

gustawdaniel commented Jul 1, 2020

Can I please to add experimentalCRUD to tutorial:

https://www.nexusjs.org/#/tutorial/chapter-5-persisting-data-via-prisma

Should I type:

import { prisma } from 'nexus-plugin-prisma'

use(prisma({
    experimentalCRUD: true
}))

?

Ok. I found example with:

use(prisma({ features: { crud: true } }))

https://github.com/graphql-nexus/examples/blob/master/plugin-prisma/api/app.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
effort/hard impact/high needs/investigation Possibly an issue, needs more analysis/research scope/architecture type/feat Add a new capability or enhance an existing one
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants