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

inferred type from a query fetching specific fields from an interface returns a type with all fields instead #180

Open
arie-finaloop opened this issue Jun 19, 2024 · 2 comments

Comments

@arie-finaloop
Copy link

Happens in 6.3.3.

type schema

interface Foo {
  id: ID!
  fooType: String!
....
  createdAt: Date!
  updatedAt: Date!
  deletedAt: Date
  publishedAt: Date
...
}

type Bar implements Foo @key(fields: "id") {
....
} 

type Baz implements Foo @key(fields: "id") {
....
} 

query

extend type Query {
...
  getFoos(input: GetFoosInput!): GetFoosResult!
...
}
type GetFoosResult {
  foos: [Foo!]!
}

type resolvers

export const typeResolvers: Resolvers = {
  Foo: {
    __resolveType: (_parent, _context) => {
      return 'Bar';
    },
  },
};

typescript function with bad return type

export const getFoosByIds = async (params: GetFoosByIds) => {
  const data = await gqlClient.query({
    getFoos: {
      __args: {
        input: {
        ...
        },
      },
      foos: {
        id: true,
        __typename: true,
      },
    },
  });
  return data.getFoos.foos[0];
}

the returning type has all fields and not only id and __typename

@arie-finaloop
Copy link
Author

looks like there is a similar issue when Foo is a union of Bar and Baz (where Bar and Baz are concrete types that share the fields of the foo "interface")

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