Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Input object can't have nested input object field #1754

Open
ashleyxue529 opened this issue Feb 17, 2024 · 5 comments
Open

Input object can't have nested input object field #1754

ashleyxue529 opened this issue Feb 17, 2024 · 5 comments

Comments

@ashleyxue529
Copy link

ashleyxue529 commented Feb 17, 2024

Setup

I have AInput that contains an inner BInput field that I want to setup like this:

@gqlInputObjectType()
export class AInput {
  @gqlField({
    class: "AInput",
    type: "BInput",
  })
  bInput: BInput;

  constructor(bInput: BInput) {
       this.bInput = bInput;
  }
}

@gqlInputObjectType()
export class BInput {
  @gqlField({
    class: "BInput",
    type: GraphQLID,
  })
  id: string;

  @gqlField({
    class: "BInput",
    type: GraphQLInt,
  })
  quantity: number;

  constructor(id: string, quantity: number) {
    this.id = id;
    this.quantity = quantity;
  }
}

But I can't regen the code due to this error:

field bInput references BInput which isn't a graphql object

I tried setting up BInput using @gqlObjectType instead, which seems to successfully regen, but the graphql type is incorrect as it needs to be an Input type not just a generic type, so the server just errors out.

Question

Should there be a separate @gqlInputField we can use? Or is there a setup I'm missing? Thanks!

@ashleyxue529
Copy link
Author

Nvmind figured out part of it, need to use custom type instead of this setup

@lolopinto
Copy link
Owner

lolopinto commented Feb 21, 2024 via email

@ashleyxue529
Copy link
Author

ashleyxue529 commented Feb 21, 2024

@lolopinto there were two setups that compiled with custom types, but only one actually generated the schema.gql file correctly

  1. [worked] Using structFields + inputType, not actually sure if I'm using it correctly but the type is correct in the gql schema
 type: {
      type: "TestInput",
      importPath: "i don't think this path does anything if we use structFields, but it is still required to be used for custom type",

      structFields: {
        id: UUIDType({ nullable: true }),
      },
      inputType: true,
 },
  1. [partially worked] Just using import paths, but no type is generated in the gql schema (is this a bug?)
@gqlInputObjectType()
class TestInput {
  @gqlField({
    class: "TestInput",
    type: GraphQLString,
  })
  id: string;

  constructor(id: string) {
    this.id = id;
  }
}

const GraphQLTestInput = new GraphQLInputObjectType({
  name: "TestInput",
  fields: (): GraphQLInputFieldConfigMap => ({
    id: {
      type: new GraphQLNonNull(GraphQLID),
    },
  }),
});

 type: {
      type: "GraphQLTestInput",
      importPath: "",
      tsType: "TestInput",
      tsImportPath: ""
 },

I think you also see this in the example you provided here, there's no ContactLabel2 type in the schema:

Looking at the example, it feels like it should work so may still be worth fixing eventually.

Do we possibly need something like @gqlInputField to differentiate? Yeah, ideally we could set it up like the example above instead of using custom types, it feels more intuitive to just nest Input Types

@ashleyxue529
Copy link
Author

ashleyxue529 commented Mar 7, 2024

Gonna reopen this as I think this is still worth updating as I ran into this again. Though please let me know if I'm just doing it wrong. Basically just trying to do:

@gqlInputObjectType()
export class CreateObjectInput {
  @gqlField({
    class: "CreateObjectInput",
    type: "[CreateObjectBInput]", <- this type is generated through the schema graphql action codegen
  })
  objectBInputs: string;
}

which gives Error: field objectBInputs references CreateObjectBInput which isn't a graphql object

@lolopinto
Copy link
Owner

lolopinto commented Mar 10, 2024

presumably, you're still using v0.1.x and not on the v0.2.0-alpha, right?

fixed in main but will need to backport a few things over for v0.1.x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants