Skip to content

Commit

Permalink
Fixing addition of node field
Browse files Browse the repository at this point in the history
  • Loading branch information
nerdsupremacist committed May 9, 2021
1 parent 1799680 commit 296c8dd
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions Sources/GraphZahl/Resolution/Root/GraphQLSchema+resolve.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ extension GraphQLSchema {

var query = try context.resolve(object: Query.self)

let mutation: GraphQLObjectType?
if Mutation.self != None.self {
mutation = try context.resolve(object: Mutation.self)
} else {
mutation = nil
}

let types = try context.types().filter { $0.name != query.name }

if !context.nodeTypes.isEmpty {
let newFields = [
"node" : nodeField(types: context.nodeTypes)
Expand All @@ -32,25 +41,18 @@ extension GraphQLSchema {
resolve: definition.resolve)
}
.merging(newFields) { $1 }

query = try GraphQLObjectType(name: query.name,
description: query.description,
fields: fields,
interfaces: query.interfaces,
isTypeOf: query.isTypeOf)
}

let mutation: GraphQLObjectType?
if Mutation.self != None.self {
mutation = try context.resolve(object: Mutation.self)
} else {
mutation = nil
}

return try GraphQL.GraphQLSchema(query: query,
mutation: mutation,
subscription: nil,
types: try context.types(),
types: types + [query],
directives: [])
}

Expand Down

0 comments on commit 296c8dd

Please sign in to comment.