Skip to content

Commit bd6bb40

Browse files
author
Auke Booij
committed
Unify two getObject methods
1 parent 1a14acd commit bd6bb40

File tree

1 file changed

+16
-20
lines changed
  • server/src-lib/Hasura/GraphQL/Schema

1 file changed

+16
-20
lines changed

server/src-lib/Hasura/GraphQL/Schema/Remote.hs

+16-20
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ remoteSchemaInterface schemaDoc defn@(G.InterfaceTypeDefinition description name
191191
P.memoizeOn 'remoteSchemaObject defn do
192192
subFieldParsers <- traverse (remoteField' schemaDoc) fields
193193
objs :: [Parser 'Output n ()] <-
194-
traverse (getObject >=> remoteSchemaObject schemaDoc) possibleTypes
194+
traverse (getObject schemaDoc name >=> remoteSchemaObject schemaDoc) possibleTypes
195195
-- In the Draft GraphQL spec (> June 2018), interfaces can themselves
196196
-- implement superinterfaces. In the future, we may need to support this
197197
-- here.
@@ -202,15 +202,6 @@ remoteSchemaInterface schemaDoc defn@(G.InterfaceTypeDefinition description name
202202
-- should have a check that expresses that that collection of objects is equal
203203
-- to 'possibelTypes'.
204204
pure $ void $ P.selectionSetInterface name description subFieldParsers objs
205-
where
206-
getObject :: G.Name -> m G.ObjectTypeDefinition
207-
getObject objectName =
208-
onNothing (lookupObject schemaDoc objectName) $
209-
case lookupInterface schemaDoc objectName of
210-
Nothing -> throw400 RemoteSchemaError $ "Could not find type " <> squote objectName
211-
<> ", which is defined as a member type of Union " <> squote name
212-
Just _ -> throw400 RemoteSchemaError $ "Union type " <> squote name <>
213-
" can only include object types. It cannot include " <> squote objectName
214205

215206
-- | 'remoteSchemaUnion' returns a output parser for a given 'UnionTypeDefinition'.
216207
remoteSchemaUnion
@@ -221,20 +212,25 @@ remoteSchemaUnion
221212
-> m (Parser 'Output n ())
222213
remoteSchemaUnion schemaDoc defn@(G.UnionTypeDefinition description name _directives objectNames) =
223214
P.memoizeOn 'remoteSchemaObject defn do
224-
objDefs <- traverse getObject objectNames
215+
objDefs <- traverse (getObject schemaDoc name) objectNames
225216
objs :: [Parser 'Output n ()] <- traverse (remoteSchemaObject schemaDoc) objDefs
226217
when (null objs) $
227218
throw400 RemoteSchemaError $ "List of member types cannot be empty for union type " <> squote name
228219
pure $ void $ P.selectionSetUnion name description objs
229-
where
230-
getObject :: G.Name -> m G.ObjectTypeDefinition
231-
getObject objectName =
232-
onNothing (lookupObject schemaDoc objectName) $
233-
case lookupInterface schemaDoc objectName of
234-
Nothing -> throw400 RemoteSchemaError $ "Could not find type " <> squote objectName
235-
<> ", which is defined as a member type of Union " <> squote name
236-
Just _ -> throw400 RemoteSchemaError $ "Union type " <> squote name <>
237-
" can only include object types. It cannot include " <> squote objectName
220+
221+
getObject
222+
:: MonadError QErr m
223+
=> SchemaIntrospection
224+
-> G.Name
225+
-> G.Name
226+
-> m G.ObjectTypeDefinition
227+
getObject schemaDoc name objectName =
228+
onNothing (lookupObject schemaDoc objectName) $
229+
case lookupInterface schemaDoc objectName of
230+
Nothing -> throw400 RemoteSchemaError $ "Could not find type " <> squote objectName
231+
<> ", which is defined as a member type of " <> squote name
232+
Just _ -> throw400 RemoteSchemaError $ "Type " <> squote name <>
233+
" can only include object types. It cannot include " <> squote objectName
238234

239235
-- | remoteSchemaInputObject returns an input parser for a given 'G.InputObjectTypeDefinition'
240236
remoteSchemaInputObject

0 commit comments

Comments
 (0)