mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-21 06:21:39 +03:00
7547786b2b
In order to respond to GraphQL queries that make use of the introspection fields `__type` or `__schema`, we need two things: - an overview of the relevant GraphQL type information, stored in a `Schema` object, and - to have included the `__type` and `__schema` fields in the `query_root` that we generate. It used to be necessary to do the above items in that order, since the `__type` and `__schema` fields (i.e. the respective `FieldParser`s) were generated _from_ a `Schema` object. Thanks to recent refactorings in `Hasura.GraphQL.Schema.Introspect` (see hasura/graphql-engine-mono#2835 or hasura/graphql-engine@5760d9289c), the introspection fields _themselves_ are now `Schema`-agnostic, and simply return a function that takes a `Schema` object after parsing. For instance, the type of `schema`, corresponding to the `__schema` field, has literally changed as follows: ```diff -schema :: MonadParse n => Schema -> FieldParser n ( J.Value) +schema :: MonadParse n => FieldParser n (Schema -> J.Value) ``` This means that the introspection fields can be included in the GraphQL schema *before* we have generated a `Schema` object. In particular, rather than the current architecture of generating `Schema` at startup time for every role, we can instead generate `Schema` ad-hoc at query parsing time, only for those queries that make use of the introspection fields. This avoids us storing a `Schema` for every role for the lifetime of the server. However: this introduces a functional change, as the code that generates the `Schema` object, and in particular the `accumulateTypeDefinitions` method, also does certain correctness checks, to prevent exposing a spec-incompliant GraphQL schema. If these correctness checks are being done at parsing time rather than startup time, then we catch certain errors only later on. For this reason, this PR adds an explicit run of this type accumulation at startup time. For efficiency reasons, and since this correctness check is not essential for correct operation of HGE, this is done for the admin role only. PR-URL: https://github.com/hasura/graphql-engine-mono/pull/3231 GitOrigin-RevId: 23701c548b785929b28667025436b6ce60bfe1cd
58 lines
1.2 KiB
Haskell
58 lines
1.2 KiB
Haskell
-- | This module exports the public API to our internal GraphQL query parser
|
|
-- combinator language. For more details, see the documentation for 'Parser'.
|
|
module Hasura.GraphQL.Parser
|
|
( Parser,
|
|
parserType,
|
|
runParser,
|
|
bind,
|
|
bindField,
|
|
bindFields,
|
|
boolean,
|
|
int,
|
|
float,
|
|
string,
|
|
identifier,
|
|
uuid,
|
|
json,
|
|
jsonb,
|
|
nonNegativeInt,
|
|
bigInt,
|
|
unsafeRawScalar,
|
|
jsonScalar,
|
|
enum,
|
|
nullable,
|
|
list,
|
|
object,
|
|
selectionSet,
|
|
safeSelectionSet,
|
|
selectionSetObject,
|
|
InputFieldsParser,
|
|
field,
|
|
fieldWithDefault,
|
|
fieldOptional,
|
|
FieldParser,
|
|
ParsedSelection (..),
|
|
handleTypename,
|
|
selection,
|
|
rawSelection,
|
|
selection_,
|
|
subselection,
|
|
rawSubselection,
|
|
subselection_,
|
|
jsonToGraphQL,
|
|
valueToJSON,
|
|
module Hasura.GraphQL.Parser.Class,
|
|
module Hasura.GraphQL.Parser.Column,
|
|
module Hasura.GraphQL.Parser.Monad,
|
|
module Hasura.GraphQL.Parser.Schema,
|
|
)
|
|
where
|
|
|
|
import Hasura.GraphQL.Parser.Class
|
|
import Hasura.GraphQL.Parser.Column
|
|
import Hasura.GraphQL.Parser.Internal.Convert
|
|
import Hasura.GraphQL.Parser.Internal.Parser
|
|
import Hasura.GraphQL.Parser.Internal.Scalars
|
|
import Hasura.GraphQL.Parser.Monad
|
|
import Hasura.GraphQL.Parser.Schema
|