Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from robak86/remove_circural_dependencies
Remove circural dependencies
- Loading branch information
Showing
40 changed files
with
592 additions
and
637 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 |
---|---|---|
@@ -1,19 +1,11 @@ | ||
import {GraphQLSchema} from "graphql"; | ||
import {someOrThrow} from "../utils/core"; | ||
import {TypeMetadata} from "../types-metadata/TypeMetadata"; | ||
import {GraphQLObjectType, GraphQLSchema} from "graphql"; | ||
import {typesResolver} from "../types-conversion/TypesResolver"; | ||
|
||
export function createSchema(annotatedRootClass, annotatedMutationClass):GraphQLSchema { | ||
let query = someOrThrow( | ||
TypeMetadata.getForClass(annotatedRootClass), | ||
'Class provided as query root is not decorated with @type'); | ||
|
||
|
||
let mutation = someOrThrow( | ||
TypeMetadata.getForClass(annotatedMutationClass), | ||
'Class provided as query root is not decorated with @type'); | ||
|
||
return new GraphQLSchema({ | ||
query: query.toGraphQLObjectType(), | ||
mutation: mutation.toGraphQLObjectType() | ||
query: typesResolver.toGraphQLType(annotatedRootClass) as GraphQLObjectType, | ||
mutation: typesResolver.toGraphQLType(annotatedMutationClass) as GraphQLObjectType | ||
}) | ||
} |
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 |
---|---|---|
@@ -1,13 +1,13 @@ | ||
import {GraphQLObjectType, GraphQLUnionType, Thunk} from "graphql"; | ||
import * as _ from 'lodash'; | ||
import {TypeProxy} from "../types-conversion/TypeProxy"; | ||
import {typesResolver} from "../types-conversion/TypesResolver"; | ||
|
||
|
||
//TODO: rename to - unionType | ||
export function createUnion(name:string, types:Thunk<Array<GraphQLObjectType | Function>>, resolveType):GraphQLUnionType { | ||
return new GraphQLUnionType({ | ||
name, | ||
types: _.castArray(types).map(type => TypeProxy.inferType(type)) as any, //TODO: fix types | ||
resolveType: (value, context) => TypeProxy.inferType(resolveType(value, context)) as any //TODO: fix types | ||
types: _.castArray(types).map(type => typesResolver.toGraphQLType(type)) as any, //TODO: fix types | ||
resolveType: (value, context) => typesResolver.toGraphQLType(resolveType(value, context)) as any //TODO: fix types | ||
}); | ||
} |
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,19 @@ | ||
import {Thunk} from "graphql"; | ||
import {resolveThunk} from "../utils/graphql"; | ||
|
||
export class TypeValue<T> { | ||
private _type:T; | ||
private _typeThunk:Thunk<T>; | ||
|
||
setType(type:T) { | ||
this._type = type; | ||
} | ||
|
||
setTypeThunk(typeThunk:Thunk<T>) { | ||
this._typeThunk = typeThunk; | ||
} | ||
|
||
inferType() { | ||
return this._type || resolveThunk(this._typeThunk); | ||
} | ||
} |
File renamed without changes.
This file was deleted.
Oops, something went wrong.
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,24 @@ | ||
import {invariant} from "../utils/core"; | ||
import * as _ from "lodash"; | ||
import {ITypeResolver} from "./abstract/ITypeResolver"; | ||
import {ParamsMetadata} from "../types-metadata/ParamsMetadata"; | ||
import {ArgumentMapResolver} from "./input/ArgumentMapResolver"; | ||
|
||
export class ArgumentsTypeResolver implements ITypeResolver { | ||
private argumentsMapBuilder:ArgumentMapResolver; | ||
|
||
constructor(protected typesResolver:ITypeResolver) { | ||
this.argumentsMapBuilder = new ArgumentMapResolver(this.typesResolver, this); | ||
} | ||
|
||
toGraphQLType(type):any { | ||
if (_.isFunction(type)) { | ||
let metadata:any = ParamsMetadata.getForClass(type); | ||
invariant(!!metadata, `Missing ParamsMetadata for ${type}. Decorate class using @params decorator`); | ||
|
||
return this.argumentsMapBuilder.toGraphQLType(metadata); | ||
} | ||
|
||
throw new Error(`Cannot infer type for ${JSON.stringify(type)}`) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.