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

Nested Unions makes compiler hang #61

Open
mbirkegaard opened this issue Nov 1, 2018 · 5 comments · May be fixed by #85
Open

Nested Unions makes compiler hang #61

mbirkegaard opened this issue Nov 1, 2018 · 5 comments · May be fixed by #85
Labels

Comments

@mbirkegaard
Copy link

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")
@mhallin
Copy link
Owner

mhallin commented Nov 2, 2018

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?

@mhallin mhallin added the bug label Nov 2, 2018
@mbirkegaard
Copy link
Author

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.

@mbirkegaard
Copy link
Author

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")

@MoOx
Copy link

MoOx commented Dec 16, 2018

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.

@andreas
Copy link

andreas commented Apr 10, 2019

@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?

johnhaley81 pushed a commit to johnhaley81/graphql_ppx that referenced this issue Jul 12, 2019
With nested queries the code was switching on the option so that it
could display a custom message. This was causing a massive increase in
compilation time as the queries got deeper and wider. In my project we
were seeing build times of about 6 minutes, after this change the build
went down to about 10-11 seconds.

Instead of displaying a custom message, the PPX will now just call out
to `Js.Option.getExn`.

This might also fix mhallin#61
@johnhaley81 johnhaley81 linked a pull request Jul 12, 2019 that will close this issue
ylecornec pushed a commit to o1-labs/graphql_ppx that referenced this issue Jun 3, 2022
…n#61)

* fix: drop env based configuration
* fix: drop env based configuration in favor of ppx-flags based
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants