graphile / crystal-pre-merge

Repository moved
https://github.com/graphile/crystal
39 stars 7 forks source link

Export: optimize `(spec => recordCodec(spec))(...)` -> `recordCodec(...)` #261

Open benjie opened 1 year ago

benjie commented 1 year ago

The exported code is full of examples like this that can be simplified.

https://astexplorer.net/#/gist/a47345bacd85d1dbfd96fe1dd8ddd38a/46ac8d567e47fa05ae3bde14fbb459cf46a0d62e

(Filed this issue because otherwise I'd just start fixing this now rather than completing what I'm meant to be working on...)

Produced via graphile-build/graphile-build-pg/src/examples/schema-export.ts where I added:

  await exportSchema(
    new GraphQLSchema({ extensions: { input } }),
    `${__dirname}/../../test-output.mjs`,
    {
      mode: "graphql-js",
      // or:
      // mode: "typeDefs",
      modules: {
        jsonwebtoken: jsonwebtoken,
      },
    },
  );
benjie commented 1 year ago

WARNING: when doing this, don't change (foo => bar(foo))(baz, qux) because that'd change the result from bar(baz) to bar(baz, qux). It's essential that the number of params passed to the IIFE is <= the number of parameters the FE accepts.