Hey having an issue with nested mutations and perm...
# prisma-whats-new
g
Hey having an issue with nested mutations and permissions. I need to check that the user has permission to add a relation to the object that is being created, but the object with that ID does not exist yet while the permission is being checked
Copy code
query ($modelModel_id: ID!, $user_id: ID!) {

  SomeModelExists(filter: {
    id: $modelModel_id
    clientCompany: {
      user:{
        id:$user_id 
      } 
    }
  })
}
n
how does the mutation look like?
g
in the above permission query, I want to make sure “model” is related to clientCompany which is related to the current user
n
hmm what kind of a permission is that?
is that the
CONNECT
permission for the corresponding relation?
g
Copy code
mutation createModel($name: String!, $clientCompanyId: ID!) {
  createModel(name: $name, clientCompanyId: $clientCompanyId, strategicObjectives: [{name: "Urgency"}, {name: "Complexity"}]) {
    id
    name
}
yes that is for connecting “model” with “strategic objective”
the relation can be modified when the model is created, or after it is created
this permission only works after the model has already been created
n
the relation can be modified when the model is created, or after it is created
is that the observed or the desired behaviour?
g
that is desired
n
I believe your permission query is setup wrong, please help me confirm that
You want to connect a company to a model, correct?
in your PQ, you say "only allow connecting a company to a model, if it is connected to the model AND its user is the authenticated user"
g
the model is being created and connected to a client company. In the same mutation, objectives are nested and connected to the model
n
can you try this PQ instead:
Copy code
query ($companyCompany_id: ID!, $user_id: ID!) {

  SomeCompanyExists(filter: {
    id: $companyCompany_id
    user: {
      id: $user_id
    }
  })
}
g
there’s no problem with connecting the model to the client company
n
this is what you really want, right? Only allow the connect operation if the company belongs to the current user
g
the problem is in connecting the model to the objective
n
Oh I'm sorry
Ah so basically you want the company to be connected first, and then the objectives
so the PQ you sent me was about the relation between model and objective, not about model and company, is that correct?
g
I want the model created and connected to the company and the objectives created and connected to the model in the same mutation
correct
n
gotcha 🙂
there's no way to control this order currently as far as I know. Could you try one thing though - that is, switching the
clientCompanyId
and
strategicObjectives
arguments in the mutation?
g
ok let me try that
no that didnt help
n
oki then I'm afraid you need to break it into separate mutations first
g
if I had access to the properties of the model I could use this query
Copy code
SomeClientCompanyExists(filter:{
    id: $modelClientCompany_id
    user: {
      id:$user_id
    }
  })
n
ah
g
any possibility of that getting in the roadmap?
n
one moment
This boils down to the fact that the order is not controllable
your PQ would still fail if the order was wrong
g
yea youre right
n
just to make sure, the company IS related to the current user?
g
yes
n
g
thanks. I’ll try to figure out a workaround for now
n
the best way would be probably to use
updateModel(strategicObjectives: [...])