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

Perf: interfaces on non-node types produce huge queries #6

Open
vladar opened this issue Aug 24, 2020 · 1 comment
Open

Perf: interfaces on non-node types produce huge queries #6

vladar opened this issue Aug 24, 2020 · 1 comment

Comments

@vladar
Copy link
Contributor

vladar commented Aug 24, 2020

Take this schema:

interface Foo {
  foo: String
  bar: Int
}

type Foo1 implements Foo {
  foo: String
  bar: Int
  baz1: String
}

#...

type Foo99 implements Foo {
  foo: String
  bar: Int
  baz99: String
}

type Problem {
  foo: Foo
  foo2: Foo
}

Now if we try to generate a fragment for the type Problem it will inline every single FooX type (assuming they are non-node types):

fragment Problem on Problem {
  foo {
    ... on Foo1 {
      foo
      bar
      baz1
    }
    # ...
    ... on Foo99 {
      foo
      bar
      baz99
    }
  }

  foo2 {
    ... on Foo1 {
      foo
      bar
      baz1
    }
    # ...
    ... on Foo99 {
      foo
      bar
      baz99
    }
  }
}

If there are many fields of this type - things can get pretty wild. One idea of how to fix this - create a separate fragment for each non-node interface type:

fragment Foo on Foo {
  foo
  bar
    ... on Foo1 {
     baz1
    }
    # ...
    ... on Foo99 {
      baz99
    }
}
fragment Problem on Problem {
  foo {
    ...Foo
  }
  foo2 {
    ...Foo
  }
}
@andris-sevcenko
Copy link

This can also happen on a schema where the interfaces are defined in a more granular manner.

interface Identifiable {
	id: Int
	uid: String
}

interface ContentEntry {
	title: String!
	body: String
}

type Entry implements Identifiable & ContentEntry{
	id: Int
	uid: String
	title: String!
	body: String
	authorId: Int
}

type Author implements Identifiable {
	id: Int
	uid: String
	name: String
}

type SearchResultSet {
	resultNodes: [Identifiable]
	pageNumber: Int
	pageCount: Int
}

When trying to generate a fragment for the type SearchResultSet, it will also inline every type that implements the Identifiable interface. As more identifiable types are added, the fragment grows.

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