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

Multiple types named "PageInfo" #27

Open
philipp-schmidt opened this issue Mar 9, 2020 · 3 comments
Open

Multiple types named "PageInfo" #27

philipp-schmidt opened this issue Mar 9, 2020 · 3 comments

Comments

@philipp-schmidt
Copy link

philipp-schmidt commented Mar 9, 2020

I'm having trouble creating a Relay'd Query like shown in this example.

My code is the following:

@Authorized([UserRole.ADMIN])
@RelayedQuery(() => User, { description: "Return all users. Permission: ADMIN." })
async allUsers(
    @RelayLimitOffset() {limit, offset}: RelayLimitOffsetArgs
): Promise<[User[], number]> {
    return await User.findAndCount({
        skip: offset,
        take: limit
    });
}

I had to change Promise<[number, User[]]> to Promise<[User[], number]> because typeorm returns it the other way around, but I don't think thats the cause of the problem.
During startup I get the following error:

UnhandledPromiseRejectionWarning: Error: Schema must contain uniquely named types but contains multiple types named "PageInfo".

I have not touched other queries except the above. The only other additions I made are the configuration steps in index.ts.

Is this somehow linked to #16 and the undefinedPageInfo type? Am I missing something? Any help very much appreciated!

@philipp-schmidt philipp-schmidt changed the title Error: Schema must contain uniquely named types but contains multiple types named "PageInfo". Multiple types named "PageInfo" Mar 9, 2020
@Superd22
Copy link
Member

Superd22 commented Mar 9, 2020

Hey.

What does your schema looks like before using AutoRelay? If you already have a type named PageInfo this will cause graphql to throw that error when AutoRelay tries to create its own PageInfo.

@philipp-schmidt
Copy link
Author

philipp-schmidt commented Mar 9, 2020

I disabled anything except the above query. So step by step, if I use the following code and do not configure auto-relay, I get the following schema:

@Authorized([UserRole.ADMIN])
@Query(() => [User], { description: "Return all users. Permission: ADMIN." })
async allUsers(): Promise<User[]> {
    return await User.find();
}
scalar DateTime

type Query {
  allUsers: [User!]!
}

type User {
  uuid: ID!
  username: String!
  fullname: String!
  role: String!
  createdAt: DateTime!
  lastLoginAt: DateTime
}

After enabling auto relay in the index.ts, the schema changes to the following:

new AutoRelayConfig({ orm: () => TypeOrmConnection })
input ConnectionArgs {
  """Paginate before opaque cursor"""
  before: String

  """Paginate after opaque cursor"""
  after: String

  """Paginate first"""
  first: Int

  """Paginate last"""
  last: Int
}

scalar DateTime

type PageInfo {
  hasNextPage: Boolean!
  hasPreviousPage: Boolean!
  startCursor: String
  endCursor: String
}

type Query {
  allUsers: [User!]!
}

type User {
  uuid: ID!
  username: String!
  fullname: String!
  role: String!
  createdAt: DateTime!
  lastLoginAt: DateTime
}

If I now change my Query to the initially provided code snippet, I get the said error. So I don't think that there are any types called PageInfo in my schema except the one auto-relay includes on its own.
Any other ideas? Thanks anyway so far!

@firmanjml
Copy link

Hello, I encountered the same issue.
I have 1 RelayQuery implemented and I don't have any Type name of PageInfo in my Schema.
Believe it was generated by the library

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

3 participants