34
34
-- performed by "Hasura.GraphQL.Execute.Resolve", but for fragment definitions
35
35
-- rather than variables.
36
36
module Hasura.GraphQL.Execute.Inline
37
- ( inlineSelectionSet ,
37
+ ( InlineMT ,
38
+ InlineM ,
39
+ inlineSelectionSet ,
40
+ inlineField ,
41
+ runInlineMT ,
42
+ runInlineM ,
38
43
)
39
44
where
40
45
@@ -74,6 +79,34 @@ type MonadInline m =
74
79
MonadState InlineState m
75
80
)
76
81
82
+ type InlineMT m a = MonadError QErr m = > (StateT InlineState (ReaderT InlineEnv m )) a
83
+
84
+ type InlineM a = InlineMT (Except QErr ) a
85
+
86
+ {-# INLINE runInlineMT #-}
87
+ runInlineMT ::
88
+ forall m a .
89
+ (MonadError QErr m ) =>
90
+ HashMap Name FragmentDefinition ->
91
+ InlineMT m a ->
92
+ m a
93
+ runInlineMT uniqueFragmentDefinitions =
94
+ flip
95
+ runReaderT
96
+ InlineEnv
97
+ { _ieFragmentDefinitions = uniqueFragmentDefinitions,
98
+ _ieFragmentStack = []
99
+ }
100
+ . flip evalStateT InlineState {_isFragmentCache = mempty }
101
+
102
+ {-# INLINE runInlineM #-}
103
+ runInlineM ::
104
+ forall a .
105
+ HashMap Name FragmentDefinition ->
106
+ InlineM a ->
107
+ Either QErr a
108
+ runInlineM fragments = runExcept . runInlineMT fragments
109
+
77
110
-- | Inlines all fragment spreads in a 'SelectionSet'; see the module
78
111
-- documentation for "Hasura.GraphQL.Execute.Inline" for details.
79
112
inlineSelectionSet ::
@@ -106,6 +139,8 @@ inlineSelectionSet fragmentDefinitions selectionSet = do
106
139
Set. toList $
107
140
Set. difference definedFragmentNames usedFragmentNames
108
141
)
142
+ -- The below code is a manual inlining of 'runInlineMT', as appearently the
143
+ -- inlining optimization does not trigger, even with the INLINE pragma.
109
144
traverse inlineSelection selectionSet
110
145
& flip evalStateT InlineState {_isFragmentCache = mempty }
111
146
& flip
@@ -128,18 +163,21 @@ inlineSelection ::
128
163
MonadInline m =>
129
164
Selection FragmentSpread Name ->
130
165
m (Selection NoFragments Name )
131
- inlineSelection (SelectionField field@ Field {_fSelectionSet}) =
132
- withPathK " selectionSet" $
133
- withPathK (unName $ _fName field) $ do
134
- selectionSet <- traverse inlineSelection _fSelectionSet
135
- pure $! SelectionField field {_fSelectionSet = selectionSet}
166
+ inlineSelection (SelectionField field) =
167
+ withPathK " selectionSet" $ SelectionField <$> inlineField field
136
168
inlineSelection (SelectionFragmentSpread spread) =
137
169
withPathK " selectionSet" $
138
170
SelectionInlineFragment <$> inlineFragmentSpread spread
139
171
inlineSelection (SelectionInlineFragment fragment@ InlineFragment {_ifSelectionSet}) = do
140
172
selectionSet <- traverse inlineSelection _ifSelectionSet
141
173
pure $! SelectionInlineFragment fragment {_ifSelectionSet = selectionSet}
142
174
175
+ {-# INLINE inlineField #-}
176
+ inlineField :: MonadInline m => Field FragmentSpread Name -> m (Field NoFragments Name )
177
+ inlineField field@ (Field {_fSelectionSet}) = withPathK (unName $ _fName field) $ do
178
+ selectionSet <- traverse inlineSelection _fSelectionSet
179
+ pure $! field {_fSelectionSet = selectionSet}
180
+
143
181
inlineFragmentSpread ::
144
182
MonadInline m =>
145
183
FragmentSpread Name ->
0 commit comments