| 200 | } |
| 201 | |
| 202 | func (e *executableSchema) Exec(ctx context.Context) graphql.ResponseHandler { |
| 203 | rc := graphql.GetOperationContext(ctx) |
| 204 | ec := executionContext{rc, e} |
| 205 | inputUnmarshalMap := graphql.BuildUnmarshalerMap( |
| 206 | ec.unmarshalInputNewCategory, |
| 207 | ec.unmarshalInputNewCourse, |
| 208 | ) |
| 209 | first := true |
| 210 | |
| 211 | switch rc.Operation.Operation { |
| 212 | case ast.Query: |
| 213 | return func(ctx context.Context) *graphql.Response { |
| 214 | if !first { |
| 215 | return nil |
| 216 | } |
| 217 | first = false |
| 218 | ctx = graphql.WithUnmarshalerMap(ctx, inputUnmarshalMap) |
| 219 | data := ec._Query(ctx, rc.Operation.SelectionSet) |
| 220 | var buf bytes.Buffer |
| 221 | data.MarshalGQL(&buf) |
| 222 | |
| 223 | return &graphql.Response{ |
| 224 | Data: buf.Bytes(), |
| 225 | } |
| 226 | } |
| 227 | case ast.Mutation: |
| 228 | return func(ctx context.Context) *graphql.Response { |
| 229 | if !first { |
| 230 | return nil |
| 231 | } |
| 232 | first = false |
| 233 | ctx = graphql.WithUnmarshalerMap(ctx, inputUnmarshalMap) |
| 234 | data := ec._Mutation(ctx, rc.Operation.SelectionSet) |
| 235 | var buf bytes.Buffer |
| 236 | data.MarshalGQL(&buf) |
| 237 | |
| 238 | return &graphql.Response{ |
| 239 | Data: buf.Bytes(), |
| 240 | } |
| 241 | } |
| 242 | |
| 243 | default: |
| 244 | return graphql.OneShot(graphql.ErrorResponse(ctx, "unsupported GraphQL operation")) |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | type executionContext struct { |
| 249 | *graphql.OperationContext |