Variable \"$_v0_where\" got invalid value

prisma

#1

Hi all,

I am quite new to Prisma and been playing around with it with success untill I ran into the following error at which I have been banging my head for a couple of hours:

Call that Is trowhing the error (ctx.db is prisma instance)

async login(parent, { email, password }, ctx: Context, info) {

const user = await ctx.db.query.user(
{
   where: { email }
});
beaddyapi_1  | Error: Variable "$_v0_where" got invalid value {"email":"toolenaar@gmail.com"}; Field "email" is not defined by type UserWhereUniqueInput.
beaddyapi_1  |     at new CombinedError (/usr/src/beaddy-api/node_modules/graphql-tools/src/stitching/errors.ts:85:5)
beaddyapi_1  |     at Object.checkResultAndHandleErrors (/usr/src/beaddy-api/node_modules/graphql-tools/src/stitching/errors.ts:107:11)
beaddyapi_1  |     at CheckResultAndHandleErrors.transformResult (/usr/src/beaddy-api/node_modules/graphql-tools/src/transforms/CheckResultAndHandleErrors.ts:15:12)
beaddyapi_1  |     at /usr/src/beaddy-api/node_modules/graphql-tools/src/transforms/transforms.ts:37:45
beaddyapi_1  |     at Array.reduce (<anonymous>)
beaddyapi_1  |     at applyResultTransforms (/usr/src/beaddy-api/node_modules/graphql-tools/src/transforms/transforms.ts:35:21)
beaddyapi_1  |     at /usr/src/beaddy-api/node_modules/graphql-tools/src/stitching/delegateToSchema.ts:81:12
beaddyapi_1  |     at step (/usr/src/beaddy-api/node_modules/graphql-tools/dist/stitching/delegateToSchema.js:32:23)
beaddyapi_1  |     at Object.next (/usr/src/beaddy-api/node_modules/graphql-tools/dist/stitching/delegateToSchema.js:13:53)
beaddyapi_1  |     at fulfilled (/usr/src/beaddy-api/node_modules/graphql-tools/dist/stitching/delegateToSchema.js:4:58)
beaddyapi_1  | Error: Variable "$_v0_where" got invalid value {"email":"toolenaar@gmail.com"}; Field "email" is not defined by type UserWhereUniqueInput.
beaddyapi_1  |     at new CombinedError (/usr/src/beaddy-api/node_modules/graphql-tools/src/stitching/errors.ts:85:5)
beaddyapi_1  |     at Object.checkResultAndHandleErrors (/usr/src/beaddy-api/node_modules/graphql-tools/src/stitching/errors.ts:107:11)
beaddyapi_1  |     at CheckResultAndHandleErrors.transformResult (/usr/src/beaddy-api/node_modules/graphql-tools/src/transforms/CheckResultAndHandleErrors.ts:15:12)
beaddyapi_1  |     at /usr/src/beaddy-api/node_modules/graphql-tools/src/transforms/transforms.ts:37:45
beaddyapi_1  |     at Array.reduce (<anonymous>)
beaddyapi_1  |     at applyResultTransforms (/usr/src/beaddy-api/node_modules/graphql-tools/src/transforms/transforms.ts:35:21)
beaddyapi_1  |     at /usr/src/beaddy-api/node_modules/graphql-tools/src/stitching/delegateToSchema.ts:81:12
beaddyapi_1  |     at step (/usr/src/beaddy-api/node_modules/graphql-tools/dist/stitching/delegateToSchema.js:32:23)
beaddyapi_1  |     at Object.next (/usr/src/beaddy-api/node_modules/graphql-tools/dist/stitching/delegateToSchema.js:13:53)
beaddyapi_1  |     at fulfilled (/usr/src/beaddy-api/node_modules/graphql-tools/dist/stitching/delegateToSchema.js:4:58)

My database model looks like this:

type User {
  id: ID! @unique
  email: String! @unique
  password: String!
  name: String!
  companies: [Company!]!
}

I am using typescript and I think it has something todo with the generation of the prisma.ts file. My graphqlconfig.yml looks like this:

projects:
  app:
    schemaPath: "src/schema.graphql"
    extensions:
      endpoints:
        default: "http://localhost:4000"
  database:
    schemaPath: "src/generated/prisma.graphql"
    extensions:
      prisma: prisma.yml
      prepare-binding:
        output: src/generated/prisma.ts
        generator: prisma-ts

And my prisma.yml:

endpoint: http://localhost:4466
datamodel: ./database/datamodel.graphql

hooks:
  post-deploy:
    - graphql get-schema --project database
    - graphql prepare

package.json

{
  "name": "beaddy-server",
  "version": "1.0.0",
  "description": "",
  "main": "src/server.ts",
  "scripts": {
    "start": "dotenv -- nodemon -e ts,graphql -x ts-node src/server.ts",
    "dev": "npm-run-all --parallel start playground",
    "playground": "graphql playground",
    "test": "echo \"Error: no test specified\" && exit 1",
    "build": "rimraf dist && tsc"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "axios": "^0.18.0",
    "bcryptjs": "^2.4.3",
    "graphql": "^0.13.2",
    "graphql-yoga": "^1.14.6",
    "jsonwebtoken": "^8.2.2",
    "lodash": "^4.17.10",
    "prisma-binding": "^2.0.2",
    "uuid": "^3.2.1"
  },
  "devDependencies": {
    "@types/bcryptjs": "^2.4.1",
    "@types/jsonwebtoken": "^7.2.7",
    "dotenv-cli": "^1.4.0",
    "graphql-playground": "^1.3.17",
    "nodemon": "^1.17.5",
    "npm-run-all": "^4.1.3",
    "rimraf": "^2.6.2",
    "ts-node": "^6.0.5",
    "typescript": "^2.8.3"
  }
}

Has anyone run into this before? Or know what I am doing wrong.


#2

Try deleting the generated files and recreating them. I had a similar problem once, and this solved it. If you are using VSCode, are you getting suggestions for email parameter?

Hope this helps you :slightly_smiling_face:


#3

@matic Did that but now the error changed to

[GraphQL error]: Message: Unknown type "UserWhereUniqueInput". Did you mean "UserWhereInput"?, Location: [object Object], Path: undefined
beaddyapi_1  | [GraphQL error]: Message: Cannot query field "user" on type "Query"., Location: [object Object], Path: undefined
beaddyapi_1  | [Network error]: Error: Unknown type "UserWhereUniqueInput". Did you mean "UserWhereInput"?
beaddyapi_1  | Error: Unknown type "UserWhereUniqueInput". Did you mean "UserWhereInput"?
beaddyapi_1  |     at BatchedGraphQLClient.<anonymous> (/usr/src/beaddy-api/node_modules/http-link-dataloader/src/BatchedGraphQLClient.ts:74:13)
beaddyapi_1  |     at step (/usr/src/beaddy-api/node_modules/http-link-dataloader/dist/src/BatchedGraphQLClient.js:40:23)
beaddyapi_1  |     at Object.next (/usr/src/beaddy-api/node_modules/http-link-dataloader/dist/src/BatchedGraphQLClient.js:21:53)
beaddyapi_1  |     at fulfilled (/usr/src/beaddy-api/node_modules/http-link-dataloader/dist/src/BatchedGraphQLClient.js:12:58)
beaddyapi_1  |     at <anonymous>
beaddyapi_1  |     at process._tickCallback (internal/process/next_tick.js:160:7)

:frowning:

Something is weird with the Types generation.


#4

@toolenaar I see. The thing is, I can only suggest what I did when I had a similar issue.

Use VSCode + TS! This will help you sort things out upfront and track bugs faster using very cool suggestions implementation.

If this still doesn’t work for you, try deleting Prisma instance, delete generated files and try deploying it once again. This is my best guess.

Tell me how it goes! :slightly_smiling_face:


#5

Hi all, I am having this same issue:

“Variable “$_v0_where” got invalid value {“email”:“EMAIL_WAS_HERE”}; Field “email” is not defined by type UserWhereUniqueInput.”

Did anyone have any luck solving it?
I have tried deleting the generated prisma.graphql file and re-creating it but nothing changes.

Thanks,
David


#6

@David_Thorpe, please share your datamodel.


#7

Hi @nilan my datamodel is as below:

type Link {
  id: ID! @unique
  createdAt: DateTime!
  description: String!
  url: String!
  postedBy: User
  votes: [Vote!]!
}

type User {
  id: ID! @unique
  name: String!
  email: String!
  password: String!
  links: [Link!]!
  votes: [Vote!]!
}

type Vote {
  id: ID! @unique
  link: Link!
  user: User!
}

The issue is happening when I use my login Mutation, defined as follows in schema.graphql:

type Mutation {
  login(email: String!, password: String!): AuthPayload
}

type AuthPayload {
  token: String
  user: User
}

type User {
  id: ID!
  name: String!
  email: String!
  links: [Link!]!
}

n.b. I am importing Link from the generated prisma.graphql file

Thanks in advance!
David


#8

Hi all and @nilan Just to let you know I have since solved this problem.

Incase anyone else has a similar problem, the issue was the email field in my type User in datamodel was not marked as @unique, once I added this all worked fine.

I found this solution in the thread linked below:

N.B. I ran prisma deploy and then graphql get-schema --project **YOUR_DATABASE_NAME_HERE**
to regenerate the schema

Thanks for your help anyway!
David


#10

Why email must be mark as unique?


Variable X got invalid value. Field “0” is not defined by type
#11

Because he’s trying to use the email as a unique identifier to fetch a single user. You could also use this query to get an array of users where the email match:

// notice users, not user
const user = await ctx.db.query.users(
{
   where: { email }
});

When querying a single record you must use a unique identifier.


#12

Thanks for explaining :smile: