-
-
Notifications
You must be signed in to change notification settings - Fork 798
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Sashko Stubailo
committed
Aug 17, 2017
1 parent
f1e9d7c
commit 5b3fe90
Showing
5 changed files
with
130 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { GraphQLObjectType, GraphQLSchema } from 'graphql'; | ||
|
||
export function resolveFromParentTypename(parent: any, schema: GraphQLSchema) { | ||
const parentTypename: string = parent['__typename']; | ||
if (!parentTypename) { | ||
throw new Error( | ||
'Did not fetch typename for object, unable to resolve interface.', | ||
); | ||
} | ||
|
||
const resolvedType = schema.getType(parentTypename); | ||
|
||
if (!(resolvedType instanceof GraphQLObjectType)) { | ||
throw new Error( | ||
'__typename did not match an object type: ' + parentTypename, | ||
); | ||
} | ||
|
||
return resolvedType; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters