Nexus: Use an inputObjectType as type for another inputObjectType

Created on 4 Mar 2019  路  3Comments  路  Source: graphql-nexus/nexus

If I try to use a inputTypeObjectType as a field for another inputObjectType like this:

export const ObjWithName = inputObjectType({
  name: 'ObjWithName',
  definition(t) {
    t.string('name');
  },
});

export const RootType = inputObjectType({
  name: 'RootType',
  definition(t) {
    t.field('obj', {type: ObjWithName});
  },
});

I get this error:

Error:(39, 21) TS2322: Type 'NexusInputObjectTypeDef<"ObjWithName">' is not assignable to type "Boolean" | "Float" | "ID" | "Int" | "JSON" | "String"'.
  Type 'NexusInputObjectTypeDef<"ObjWithName">' is not assignable to type '"String"'.

But I don't het this error if I try the same thing with objectType:

export const ObjWithName = objectType({
  name: 'ObjWithName',
  definition(t) {
    t.string('name');
  },
});

export const RootType = objectType({
  name: 'RootType',
  definition(t) {
    t.field('obj', {type: ObjWithName});
  },
});

I tried playing around with the type here to look more like this. But I couldn't make it work to make a PR x.x

Thanks!

scoptypes typbug

Most helpful comment

Fixed & released in 0.11

All 3 comments

Cool, I agree this should work, will investigate!

I'm facing the same issue. Thanks @tgriesser in advance!

Fixed & released in 0.11

Was this page helpful?
0 / 5 - 0 ratings

Related issues

StevenLangbroek picture StevenLangbroek  路  6Comments

huv1k picture huv1k  路  6Comments

jasonkuhrt picture jasonkuhrt  路  3Comments

delianides picture delianides  路  6Comments

capaj picture capaj  路  5Comments