dillonkearns / elm-graphql

Autogenerate type-safe GraphQL queries in Elm.

Home Page:https://package.elm-lang.org/packages/dillonkearns/elm-graphql/latest

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Generating graphql bindings takes a long time

Munksgaard opened this issue · comments

We're happy users of elm-graphql, except for the fact that running it takes a long time.

Currently it takes over two minutes on my local system to generate the bindings, while it sometimes takes upwards of five minutes on our CI system. I realize that a lot files are being created, but it's a bit annoying when iterating on graphql layouts. Our database isn't huge by any means (61 tables), so two minutes seem a bit excessive.

Here are some stats from our system:

# Generating bindings
 $ time make elm-graphql
test -n "http://localhost:5000/graphql"  # $GRAPHQL_ENDPOINT
npx @dillonkearns/elm-graphql "http://localhost:5000/graphql" \
  --output generated \
  --scalar-codecs CustomScalarCodecs \
  --base Foo
Fetching GraphQL schema...
Generating files...
Success!

real	2m17.865s
user	2m17.590s
sys	0m0.626s
# In the directory of the generated bindings
$ find . -type f -exec wc -l {} \+ | tail -n 1
 125893 total

$ du -hs
7.6M	.

Is there any way to speed up the creation of the bindings?

For reference, I'm using elm-graphql version 3.6.2, and my GraphQL api is created by PostGraphile.

Hello @Munksgaard, thanks for sharing those details, I actually hadn't heard of slow performance running elm-graphql before. Not sure if that's because it doesn't come up often, or people are willing to tolerate it, or run it only when the schema changes.

Would you be able to share your schema with me? You could share it in GraphQL SDL format, or the JSON dump of the introspection query. If you can't share it publicly, then you could also send it to me privately on the Elm slack.

I'm not sure if I'll be able to dedicate time to it in the near-term, but I would like to do a quick performance profile so I can see where the bottlenecks are and get a sense of whether there is any low hanging fruit.

Hello! Just pinging back on this. If you're willing to share your schema, or do some profiling using the node profiler, I'd be interested to see what's causing the bottleneck. Thanks!

Hi @dillonkearns!

I believe we already discussed this on slack once, long ago. I think we figured out that the basic problem was just that I had a lot of stuff in my graphql schema. If you want, I can send it to you on slack again, so we can reconfirm the cause?

Oh that sounds familiar, sorry I lost track of that! Yes, you can reach out on Slack again and I'll take a look. Thank you!

Also, with the latest release, you can run elm-graphql --skip-elm-format. Could you see how the timing compares with and without that flag, and share the numbers? That would be a useful data point.

I'll close this since I haven't heard back, but if anyone else has problems here then it would be great to get some numbers and schemas that reproduce a slow generate step 👍

Sharing a JSON file or .graphql file with the schema would be a good way to share that.