graphqless-js

Statically compiled resolvers for entire queries based on a graphql-js schema.

MIT License

Stars
7
Committers
1

graphqless

Statically compiled resolvers for entire queries based on a graphql-js schema. That is, for a operation document and an executable schema, the graphqless compiler will output JavaScript code that is able to execute that operation without any GraphQL runtime execution overhead such as parsing, validating, and figuring out what resolvers to invoke.

⚠️ This is currenntly a proof-of-concept implementation to research feasability and uncover considerations to take into account. Any such considerations will be disucced in the issue tracker.

Example

Turns this:

query SomeQuery {
  anObjectRootField {
    aNestedScalarField
  }
}

into this:

;(function SomeQuery(schema, rootValue) {
  return {
    data: {
      anObjectRootField: (function () {
        const result_1 = schema
          .getType("Query")
          .toConfig()
          .fields.anObjectRootField.resolve(rootValue, {}, undefined)

        if (result_1) {
          return Object.assign({}, result_1, {
            aNestedScalarField: schema
              .getType("AnObjectRootFieldType")
              .toConfig()
              .fields.aNestedScalarField.resolve(result_1, {}, undefined, {}),
          })
        }
      })(),
    },
  }
})