Input Types in Nexus



I am really stuck on create an input type in nexus at the moment.

so here is my code.

const myInput = EmployeeWhereInput({
    name: 'EmployeeWhereInput',
    definition( t ) {
        t.field('company', {
            type: 'Company'

I get the error:
Error: Expected Employee to be a possible input type, saw GraphQLObjectType.

So I have a type called Employee in my schema and a type called Company. Each employee has a one-to-one relationship with a company. How to I add this to my Input?

This is really confusing me and holding me back.



here is the documentation for input types in nexus:

so you code will be:

import { objectType, inputObjectType, scalarType } from 'nexus';

const Company = objectType({
  name: "Company",
  definition(t) {"id")

const EmployeeWhereInput = inputObjectType({
  name: "EmployeeWhereInput",
  definition(t) {
    t.field("company", { type: Company })


Ah, so I have to import my actual objectType for that field. I have read all of nexus’s documentation and have tried to understand the code when I have a difficult time, but I don’t understand typescript very much, so it is difficult. I would like to add to the documentation once I am finished with my project. How can I contribute?


I am now getting the error:

Expected [object Object] to be possible input type, saw GraphQLObjectType

I imported the objectType into the file that I defined my inputObjectType and placed it into the field as you did. Could this be a bug?

I think I will create a public prisma project so that others can see how certain things are implemented and developed, as well as help with this issue.


I made a barebones project to make it easier and less time-consuming to learn nexus. I made an input successfully, but how do I add the input to a query as an argument. fieldArg right?


I figured it out. Thanks for pointing me in the right direction :).


Also a small tip, whenever you are unsure use the SDL converter.


I used the schema converter and exported the types from what it gave me and I am now getting an error from nexus stating

TypeError: schema.getTypeMap is not a function
    at forEachField (/home/developer/Documents/nexus-example/src/node_modules/graphql-extensions/lib/index.js:157:26)
    at Object.enableGraphQLExtensions (/home/developer/Documents/nexus-example/src/node_modules/graphql-extensions/lib/index.js:106:5)
    at doRunQuery (/home/developer/Documents/nexus-example/src/node_modules/apollo-server-core/dist/runQuery.js:67:30)
    at /home/developer/Documents/nexus-example/src/node_modules/apollo-server-core/dist/runQuery.js:21:56
    at process._tickCallback (internal/process/next_tick.js:68:7)
Error: Expected { _extensionsEnabled: true } to be a GraphQL schema.
    at invariant (/home/developer/Documents/nexus-example/src/node_modules/graphql/jsutils/invariant.js:19:11)
    at assertSchema (/home/developer/Documents/nexus-example/src/node_modules/graphql/type/schema.js:38:46)
    at validateSchema (/home/developer/Documents/nexus-example/src/node_modules/graphql/type/validate.js:51:28)
    at assertValidSchema (/home/developer/Documents/nexus-example/src/node_modules/graphql/type/validate.js:75:16)
    at Object.validate (/home/developer/Documents/nexus-example/src/node_modules/graphql/validation/validate.js:55:35)
    at doRunQuery (/home/developer/Documents/nexus-example/src/node_modules/apollo-server-core/dist/runQuery.js:111:42)
    at /home/developer/Documents/nexus-example/src/node_modules/apollo-server-core/dist/runQuery.js:21:56
    at process._tickCallback (internal/process/next_tick.js:68:7)



Please open an issue in the nexus repository about this :pray:


Will do, just wanted to see if I did something wrong or it was something with nexus.



I figured out the issue I was having, but ran into another issue immediately after that one. I am completely lost on this issue.

Error: Cannot return null for non-nullable field Mutation.createUser.
    at completeValue (/home/developer/Documents/nexus-example/src/node_modules/graphql/execution/execute.js:568:13)
    at completeValueCatchingError (/home/developer/Documents/nexus-example/src/node_modules/graphql/execution/execute.js:503:19)
    at resolveField (/home/developer/Documents/nexus-example/src/node_modules/graphql/execution/execute.js:447:10)
    at /home/developer/Documents/nexus-example/src/node_modules/graphql/execution/execute.js:262:18
    at /home/developer/Documents/nexus-example/src/node_modules/graphql/jsutils/promiseReduce.js:32:10
    at Array.reduce (<anonymous>)
    at promiseReduce (/home/developer/Documents/nexus-example/src/node_modules/graphql/jsutils/promiseReduce.js:29:17)
    at executeFieldsSerially (/home/developer/Documents/nexus-example/src/node_modules/graphql/execution/execute.js:259:37)
    at executeOperation (/home/developer/Documents/nexus-example/src/node_modules/graphql/execution/execute.js:237:55)
    at executeImpl (/home/developer/Documents/nexus-example/src/node_modules/graphql/execution/execute.js:85:14)

I noticed that all of the schema types don’t have a resolver. Do I have to implement them myself? I tried to add a resolver and playground stopped outputting responses.


This topic was automatically closed 45 days after the last reply. New replies are no longer allowed.