Skip to content

Using inputObjectType as an argument type #295

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

Closed
nayaabkhan opened this issue Oct 30, 2019 · 1 comment
Closed

Using inputObjectType as an argument type #295

nayaabkhan opened this issue Oct 30, 2019 · 1 comment

Comments

@nayaabkhan
Copy link

nayaabkhan commented Oct 30, 2019

Is it possible with Nexus to use an inputObjectType as a type for an argument? I see it works well for scalars and enums but fails for an inputObjectType:

export const User = objectType({
  name: 'User',
  description: 'Represents a User.',
  definition(t) {
    t.implements(Node)
    t.field('inbox', {
      type: MessageConnection,
      description: 'A list of messages in the inbox.',
      args: {
        first: intArg({
          description: 'Returns the first n elements from the list.',
        }),
        last: intArg({
          description: 'Returns the last n elements from the list.',
        }),
        orderBy: arg({
          // Type 'NexusInputObjectTypeDef<"MessageOrder">' is not assignable to type 'NexusArgConfigType<"OrderDirection" | "Boolean" | "Float" | "ID" | "Int" | "String">'.
          type: MessageOrder,
          description:
            'Ordering options for messages returned from the connection.',
        }),
      },
    })
  },
})

export const MessageOrder = inputObjectType({
  name: 'MessageOrder',
  description: 'Ordering options for message connections.',
  definition(t) {
    t.field('direction', {
      type: OrderDirection,
      required: true,
      description: 'The ordering direction.',
    })
    t.field('field', {
      type: MessageOrderField,
      required: true,
      description: 'The field to order messages by.',
    })
  },
})

export const MessageOrderField = enumType({
  name: 'MessageOrderField',
  description: 'Properties by which message connections can be ordered.',
  members: [
    {
      description: 'Order messages by creation time.',
      name: 'CREATED_AT',
      value: 'CREATED_AT',
    },
  ],
})
@nayaabkhan
Copy link
Author

Sorry for the false alarm, was able to fix the issue by running my development server with transpile flag as suggested here: prisma-labs/graphql-framework-experiment#77 (comment).

Leaving here in case someone else comes looking for help:

{
  "scripts": {
    "develop": "ts-node-dev --no-notify --transpile-only --respawn ./src/index.ts"
  }
}

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

1 participant