Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added embedded Typescript definitions. #120

Merged
merged 5 commits into from
Sep 6, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# Changelog

### vNEXT
* Fix multiple issues in addMockFunctionsToSchema when preserveResolvers is true (support for Promises, and props defined using Object.defineProperty) ([@sebastienbarre](https://github.com/sebastienbarre) in [#115]((https://github.com/apollostack/graphql-tools/pull/115))
* Added embedded Typescript definitions ([@DxCx](https://github.com/DxCx) in [#120](https://github.com/apollostack/graphql-tools/pull/120))

* Make allowUndefinedInResolve true by default ([@jbaxleyiii](https://github.com/jbaxleyiii) in [#117]((https://github.com/apollostack/graphql-tools/pull/117))
* Fix multiple issues in addMockFunctionsToSchema when preserveResolvers is true (support for Promises, and props defined using Object.defineProperty) ([@sebastienbarre](https://github.com/sebastienbarre) in [#115](https://github.com/apollostack/graphql-tools/pull/115))

* Make allowUndefinedInResolve true by default ([@jbaxleyiii](https://github.com/jbaxleyiii) in [#117](https://github.com/apollostack/graphql-tools/pull/117))

* Add `requireResolversForAllFields` resolver validation option ([@nevir](https://github.com/nevir) in [#107](https://github.com/apollostack/graphql-tools/pull/107))

Expand Down
68 changes: 68 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Type definitions for graphql 0.6.5
// Project: https://github.com/apollostack/graphql-tools
// Definitions by: Hagai Cohen <https://github.com/DxCx>

import { GraphQLSchema, GraphQLFieldDefinition, GraphQLResolveInfo, GraphQLResult } from "graphql";

// schemaGenerator.js
interface IResolverValidationOptions {
requireResolversForArgs?: boolean;
requireResolversForNonScalar?: boolean;
requireResolversForAllFields?: boolean;
}

type ITypedef = (() => string) | string;
type ITypeDefinitions = string | Array<ITypedef>;
type IResolveFn = (rootObject: any, args: { [key: string]: any }, context: any, info: GraphQLResolveInfo) => any;
type IResolverObject = { [key: string]: IResolveFn };
type IResolvers = { [key: string]: IResolverObject };
interface ILogger {
log: (message: string) => void;
}

interface IConnector {
new (context: any): any;
}
type IConnectors = { [key: string]: IConnector };

interface IExecutableSchemaDefinition {
typeDefs: ITypeDefinitions;
resolvers: IResolvers;
connectors?: IConnectors;
logger?: ILogger;
allowUndefinedInResolve?: boolean;
resolverValidationOptions?: IResolverValidationOptions;
}

type IFieldIteratorFn = (fieldDef: GraphQLFieldDefinition, typeName: string, fieldName: string) => void;

export function makeExecutableSchema(definition: IExecutableSchemaDefinition): GraphQLSchema;
export function buildSchemaFromTypeDefinitions(definition: ITypeDefinitions): GraphQLSchema;
export function addErrorLoggingToSchema(schema: GraphQLSchema, logger: ILogger): void;
export function forEachField(schema: GraphQLSchema, fn: IFieldIteratorFn);
export function addResolveFunctionsToSchema(schema: GraphQLSchema, resolveFunctions: IResolvers);
export function addCatchUndefinedToSchema(schema: GraphQLSchema);
export function assertResolveFunctionsPresent(schema: GraphQLSchema, addCatchUndefinedToSchema: IResolverValidationOptions);
export function addSchemaLevelResolveFunction(schema: GraphQLSchema, fn: IResolveFn);
export function attachConnectorsToContext(schema: GraphQLSchema, connectors: IConnectors);

// mock.js
type IMockFn = () => any;
type IMocks = { [key: string] : IMockFn };

interface IMockOptions {
schema: GraphQLSchema;
mocks?: IMocks;
preserveResolvers?: boolean;
}

interface IMockServer {
query: (query: string, vars: { [key: string]: any }) => Promise<GraphQLResult>;
}

export function mockServer(schema: GraphQLSchema, mocks: IMocks, preserveResolvers: boolean): IMockServer;
export function addMockFunctionsToSchema(mockOptions: IMockOptions): void;
export class MockList {
constructor (len: number | Array<number>, wrappedFunction?: IMockFn);
public mock(root: any, args: { [key: string]: any }, context: any, info: any, fieldType: any, mockTypeFunc: IResolveFn);
}
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "0.6.5",
"description": "A set of useful GraphQL tools",
"main": "dist/index.js",
"typings": "index.d.ts",
"directories": {
"test": "test"
},
Expand Down Expand Up @@ -35,7 +36,8 @@
"node-uuid": "^1.4.7"
},
"peerDependencies": {
"graphql": "^0.5.0 || ^0.6.0 || ^0.7.0"
"graphql": "^0.5.0 || ^0.6.0 || ^0.7.0",
"graphql-typings": "^0.0.1-beta-2"
},
"devDependencies": {
"babel-cli": "^6.6.5",
Expand All @@ -57,6 +59,7 @@
"express3": "0.0.0",
"fs": "0.0.2",
"graphql": "^0.7.0",
"graphql-typings": "^0.0.1-beta-2",
"istanbul": "1.0.0-alpha.2",
"lodash": "^4.10.0",
"mocha": "^3.0.1",
Expand Down