Is there a way to deactivate massively the create ...
# orm-help
m
Is there a way to deactivate massively the create input (I only want the connect one) in all the mutations with prisma or nexus? I know how do it, but one by one with nexus, filtering this property but I would like to know if exists some way to do it massively.
c
why would you want to do this?
is all your data seeded? you never create data?
also why would it matter if the function is there, your yoga/apollo server layer just would never call it
seems kind of pointless
j
this worked for me
Copy code
export const Mutation = prismaObjectType({
  name: 'Mutation',

  definition(t) {
    t.prismaFields(['*']);
    t.field('signup', {
      type: 'AuthPayload',
      args: {
        name: stringArg({ nullable: true }),
        email: stringArg(),
        password: stringArg(),
      },
      resolve: async (parent, { name, email, password }, ctx) => {
        const hashedPassword = await hash(password, 10);
        const user = await ctx.prisma.createUser({
          name,
          email,
          password: hashedPassword,
        });
        return {
          token: sign({ userId: user.id }, APP_SECRET),
 
          user,
        };
      },
});
so I mixed
t.prismaFields(['*']);
with the rest of the specific definitions
m
I'm using a proxy before of prisma server, and in this proxy I'm hiding some mutations, but if I'm creating a entity, I don't want to allow to create a new nested entity, I would like users use main mutation to do it, only allow to link with an existent nested entity.
c
you are forwarding mutations directly from the user to prisma
and using prisma syntax
m
@Jorge here you only has extending the mutations with a custom one, I'm talking about hide some properties in all the inputs.
c
at least I get the use case
though seems like a bad idea to forward mutations to prisma
m
It's a main proxy, not a bad idea for us because this proxy includes 3 or 4 schemas of different servers.
Well, using a proxy or not, I would hide them in my prisma server, if I have to declare a type extending one by one these inputs, I will do it like this if there isn't any other way.
Thanks!
c
you mean schema stitching
m
Yes
c
just seems dangerous to let end users run prisma mutations directly
incase you miss filtering something
can destroy data, modify, etc
usually you create a curated graphql api between the other schemas
graphql yoga/apollo server w/e
m
In this proxy we have the auth part analyzing his bearer
Right, this proxy uses apollo server
c
right... you are basically calling graphql yoga a proxy
m
exactly
c
right, pretty much everyone using prisma uses an apollo server
its not like that part is different
I would just be cautious about forwarding the queries directly
even checking auth, if they are authed there is no permissions on the actual mutation
m
Yes, don't worry about that 😄
c
seems like someone who knew how prisma worked could really mess with your data, I dunno
m
I analize individual claims to know what the user can execute or not
c
so you are creating an API on top of prisma... which is the norm
m
Prisma server will not be public, only apollo server
c
yea I get that
but it sounded like you are letting the user pass mutation objects directly to prisma
if you are writing an API on top, why do you care if the prisma create functions are there
m
No no..
c
since you have a schema on top anyways
and they arent accessible in that schema
thats what I said at the beginning
m
Because I do a executable schema and I expose it directly, but analyzing the permissions, and I'm hiding some mutations (e.g. main entities) and these inputs that I want to hide too, are about these main entities.
c
so you do expose prisma to the end user
you are inspecting the object you send to prisma
with permissions
that sure seems way more tedious than just writing a clean API on top
🤷‍♂️
seems like a backwards way to go about it to me
u
Hi @Martí Crespí out of curiosity are you stitchingwith
graphql-tools
? I created this issue/question to see how people do that with nexus: https://github.com/prisma/nexus/issues/70 At which point do you analyse those claims @Martí Crespí? Did you create another graphql server on which you do that?
m
Hi @Uby, yes I'm stitching with graphql-tools, and then I'm serving it with apollo server. And before to send the operation to sub servers, I analize the claims with an apollo link allowing or denying the current operation.
u
I am doing something similar for an admin application, but for the public application I am putting another graphql server in between my stitched one and the client. So that like @CCBCodeMonkey said you don’t let someone being able to introspect and see all you can do on your backend.
Also @Martí Crespí you might be interested in this too: https://github.com/prisma/nexus-prisma/issues/129
m
Right, it's as you're saying.. Perfect! I will take a look at these links! Many thanks!
👍 1