mhallin / graphql_ppx

GraphQL PPX rewriter for Bucklescript/ReasonML

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Nested Unions makes compiler hang

mbirkegaard opened this issue · comments

I'm having an issue with GraphQL queries with nested unions causing the compiler to hang.

I'm trying to do something like the following

module Notifications = [%graphql {|
  query Notifications($limit: Int) {
  notifications(limit: $limit) {
    id
    createdAt {
      notification {
        ... on TypeA {
          aField
        }
        ... on TypeB {
          bField
          matches {
            ... on MatchC {
              cField
            }
            ... on MatchD {
              dField
            }
          }
        }
      }
    }
  }
}
|}];

If I remove the matches field, the query compiles in a few seconds (which seems a bit slow compared to normal).

I can't quite figure out whether this is an unsupported feature mentioned in the README but I wouldn't think so, given that it's normal unions of objects all the way down.

I wanted to try to diagnose it by setting the -verbose flag in bsconfig.json following the example given for -ast-out, but that just produced an error

Fatal error: exception Failure("graphql_ppx/ppx\\ -verbose not found when resolving ppx-flags")

I haven't done any profiling on larger schemas so it's unfortunately possible that there are accidentally quadratic behaviors lurking here and there.

Regarding your schema:

  • How many object types do you have, roughly? Like; 10, 100, 1000, more? :)
  • How many types are part of the unions, roughly?

There's (very roughly) about 150-ish object types in the schema.

For the second question: Do you mean just the union objects themselves or do you mean how many types are being selected in the unions? If it's the former then the notification field is a union of three types, where the TypeA selection contains no union, while the TypeB selection contains two fields of the same union type of two types. The third type of the topmost union isn't used.

Can you give any pointers on how to diagnose this issue? I've now encountered it in queries with only a single union.

I wanted to try to diagnose it by setting the -verbose flag in bsconfig.json following the example given for -ast-out, but that just produced an error

Fatal error: exception Failure("graphql_ppx/ppx\\ -verbose not found when resolving ppx-flags")

I am facing similar issue where a query could take around 40s to compile.

If you want to reproduce use this server https://dame.bio/graphql and try the following query

query {
    posts(first: 1, where: {name: "brownie-sans-beurre-et-sans-gluten-aux-noix-du-bresil"}) {
      edges {
        node {
          id
          title
          slug
          commentCount
          likeCount
          postId
          dateGmt
          content
          comments(first: 1000) {
            nodes {
              commentId
              parent {
                commentId
              }
              dateGmt
              content
              
              author {
                ... on User {
                  userId
                  name
                  url
                  email
                }
                ... on CommentAuthor {
                  name
                  url
                  email
                }
              }
            }
          }
          categories {
            nodes {
              name
              slug
              parent {
                id
              }
            }
          }
          tags {
            nodes {
              name
              slug
            }
          }
        }
      }
    }
  }

Notes

  • if I remove parent { commentId } part, file compile instantly.
  • if I remove the union (the entire author part) obviously, file compile instantly.

Hope this will help to trace the source of the issue.

@MoOx Is this still an issue for you? I cannot replicate with the provided query and server -- the query compiles instantly. I'm not sure if something changed on the server, so it would be great if you could provide the graphql_schema.json which causes this.

@mbirkegaard Can you provide a graphql_schema.json to go with the query to reproduce the issue?