mirror of
https://github.com/Airsequel/AirGQL.git
synced 2025-07-31 02:06:44 +03:00
Migrate all gql code to share types with introspection
This commit is contained in:
parent
4318c70053
commit
9cebb6dc2d
4 changed files with 364 additions and 828 deletions
source/AirGQL
File diff suppressed because it is too large
Load diff
|
@ -3,6 +3,9 @@ module AirGQL.Introspection (
|
|||
getSchemaResolver,
|
||||
tableQueryField,
|
||||
tableQueryByPKField,
|
||||
tableInsertField,
|
||||
tableUpdateField,
|
||||
tableDeleteField,
|
||||
)
|
||||
where
|
||||
|
||||
|
@ -411,13 +414,12 @@ getSchema accessMode tables = do
|
|||
|
||||
-- We make this toplevel, because putting it inside `getSchemaResolver`
|
||||
-- means haskell will evaluate it each time, which leads to each execution
|
||||
-- taking 2-3s
|
||||
makeSchemaResolver :: Either Text (Type.Schema -> Resolver IO)
|
||||
makeSchemaResolver = do
|
||||
let schemaField = Type.field "__schema" $ Type.nonNull Type.typeSchema
|
||||
ty <- makeType schemaField.type_
|
||||
let gqlField = Out.Field schemaField.description ty mempty
|
||||
pure $ \schema -> Out.ValueResolver gqlField $ pure $ toGraphQL schema
|
||||
-- taking 2-3 additional seconds
|
||||
schemaField :: Either Text (Out.Field IO)
|
||||
schemaField = do
|
||||
let field = Type.field "__schema" $ Type.nonNull Type.typeSchema
|
||||
ty <- makeType field.type_
|
||||
pure $ Out.Field field.description ty mempty
|
||||
|
||||
|
||||
getSchemaResolver
|
||||
|
@ -425,8 +427,9 @@ getSchemaResolver
|
|||
-> [TableEntry]
|
||||
-> IO (HashMap Text (Resolver IO))
|
||||
getSchemaResolver accessMode tables = do
|
||||
case makeSchemaResolver of
|
||||
Right make -> do
|
||||
case schemaField of
|
||||
Right field -> do
|
||||
let schema = getSchema accessMode tables
|
||||
pure $ HashMap.singleton "__schema" $ make schema
|
||||
let resolver = Out.ValueResolver field $ pure $ toGraphQL schema
|
||||
pure $ HashMap.singleton "__schema" resolver
|
||||
Left err -> fail $ T.unpack err
|
||||
|
|
|
@ -672,10 +672,10 @@ resolveReferencesConstraint tables referencedTable = do
|
|||
tables
|
||||
let columns = table.columns
|
||||
let pks = P.filter (\column -> column.primary_key) columns
|
||||
let nonRowidPks = P.filter (\column -> column.isRowid) pks
|
||||
case nonRowidPks of
|
||||
[] -> pure "rowid"
|
||||
[column] -> pure column.column_name
|
||||
let nonRowidPks = P.filter (\column -> P.not column.isRowid) pks
|
||||
column <- case nonRowidPks of
|
||||
[] -> P.find (\column -> column.isRowid) pks
|
||||
[column] -> pure column
|
||||
-- Note: we currently do not support having composite primary keys
|
||||
-- referenced implicitly, as that would lead to multiple complications like:
|
||||
-- - figuring out the correct order for the references
|
||||
|
@ -685,6 +685,7 @@ resolveReferencesConstraint tables referencedTable = do
|
|||
-- do it as long as we keep track of the column order. Not sure it's worth the
|
||||
-- hassle though...
|
||||
_ -> Nothing
|
||||
pure column.column_name
|
||||
|
||||
|
||||
-- See the docs for `resolveReferencesConstraint` for details
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue