Skip to content
This repository was archived by the owner on Apr 13, 2023. It is now read-only.

migrate from typed-graphql to @types/graphql #393

Merged
merged 1 commit into from
Jan 5, 2017
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
4 changes: 3 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"files.exclude": {
"**/.git": true,
"**/.DS_Store": true,
"node_modules": true,
"node_modules": false,
"scripts": true,
"test-lib": true,
"lib": false,
Expand All @@ -22,4 +22,6 @@
"tslint.json": true,
"coverage": true
}
,
"typescript.tsdk": "./node_modules/typescript/lib"
}
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,14 @@
"README.md"
],
"peerDependencies": {
"apollo-client": "^0.4.21 || ^0.5.1",
"apollo-client": "^0.4.21 || ^0.5.1 || ^0.6.0",
"react": "0.14.x || 15.* || ^15.0.0",
"redux": "^2.0.0 || ^3.0.0"
},
"devDependencies": {
"@types/chai": "^3.4.33",
"@types/enzyme": "^2.4.32",
"@types/graphql": "^0.8.5",
"@types/immutable": "^3.8.3",
"@types/invariant": "^2.2.27",
"@types/isomorphic-fetch": "0.0.30",
Expand All @@ -85,7 +86,7 @@
"@types/redux-form": "^4.0.29",
"@types/redux-immutable": "^3.0.30",
"@types/sinon": "^1.16.29",
"apollo-client": "0.5.13",
"apollo-client": "0.6.0",
"babel-jest": "^14.1.0",
"babel-preset-react-native": "^1.9.0",
"browserify": "^13.0.0",
Expand Down Expand Up @@ -121,13 +122,13 @@
"swapi-graphql": "0.0.4",
"travis-weigh-in": "^1.0.2",
"tslint": "^3.6.0",
"typed-graphql": "^1.0.2",
"typescript": "^2.0.3",
"typescript-require": "^0.2.9-1",
"typings": "^0.7.9",
"uglify-js": "^2.6.2"
},
"dependencies": {
"graphql-anywhere": "^2.0.0",
"hoist-non-react-statics": "^1.2.0",
"invariant": "^2.2.1",
"lodash.flatten": "^4.2.0",
Expand Down
11 changes: 5 additions & 6 deletions src/graphql.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,16 @@ import ApolloClient, {
} from 'apollo-client';

import {
// GraphQLResult,
Document,
FragmentDefinition,
DocumentNode,
FragmentDefinitionNode,
} from 'graphql';

import { parser, DocumentType } from './parser';

export declare interface MutationOptions {
variables?: Object;
resultBehaviors?: MutationBehavior[];
fragments?: FragmentDefinition[] | FragmentDefinition[][];
fragments?: FragmentDefinitionNode[] | FragmentDefinitionNode[][];
optimisticResponse?: Object;
updateQueries?: MutationQueryReducersMap;
forceFetch?: boolean;
Expand All @@ -47,7 +46,7 @@ export declare interface QueryOptions {
returnPartialData?: boolean;
noFetch?: boolean;
pollInterval?: number;
fragments?: FragmentDefinition[] | FragmentDefinition[][];
fragments?: FragmentDefinitionNode[] | FragmentDefinitionNode[][];
// deprecated
skip?: boolean;
}
Expand Down Expand Up @@ -122,7 +121,7 @@ export interface OperationOption {
}

export default function graphql(
document: Document,
document: DocumentNode,
operationOptions: OperationOption = {}
) {

Expand Down
23 changes: 12 additions & 11 deletions src/parser.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import {
Document,
VariableDefinition,
OperationDefinition,
DocumentNode,
DefinitionNode,
VariableDefinitionNode,
OperationDefinitionNode,
} from 'graphql';

import invariant = require('invariant');
Expand All @@ -15,11 +16,11 @@ export enum DocumentType {
export interface IDocumentDefinition {
type: DocumentType;
name: string;
variables: VariableDefinition[];
variables: VariableDefinitionNode[];
}

// the parser is mainly a safety check for the HOC
export function parser(document: Document): IDocumentDefinition {
export function parser(document: DocumentNode): IDocumentDefinition {
// variables
let variables, type, name;

Expand All @@ -30,23 +31,23 @@ export function parser(document: Document): IDocumentDefinition {
*/
invariant((!!document || !!document.kind),
// tslint:disable-line
`Argument of ${document} passed to parser was not a valid GraphQL Document. You may need to use 'graphql-tag' or another method to convert your operation into a document`
`Argument of ${document} passed to parser was not a valid GraphQL DocumentNode. You may need to use 'graphql-tag' or another method to convert your operation into a document`
);

const fragments = document.definitions.filter(
(x: OperationDefinition) => x.kind === 'FragmentDefinition'
(x: DefinitionNode) => x.kind === 'FragmentDefinition'
);

const queries = document.definitions.filter(
(x: OperationDefinition) => x.kind === 'OperationDefinition' && x.operation === 'query'
(x: DefinitionNode) => x.kind === 'OperationDefinition' && x.operation === 'query'
);

const mutations = document.definitions.filter(
(x: OperationDefinition) => x.kind === 'OperationDefinition' && x.operation === 'mutation'
(x: DefinitionNode) => x.kind === 'OperationDefinition' && x.operation === 'mutation'
);

const subscriptions = document.definitions.filter(
(x: OperationDefinition) => x.kind === 'OperationDefinition' && x.operation === 'subscription'
(x: DefinitionNode) => x.kind === 'OperationDefinition' && x.operation === 'subscription'
);

if (fragments.length && (!queries.length || !mutations.length || !subscriptions.length)) {
Expand Down Expand Up @@ -75,7 +76,7 @@ export function parser(document: Document): IDocumentDefinition {
);
}

const definition = definitions[0] as OperationDefinition;
const definition = definitions[0] as OperationDefinitionNode;
variables = definition.variableDefinitions || [];
let hasName = definition.name && definition.name.kind === 'Name';
name = hasName ? definition.name.value : 'data'; // fallback to using data if no name
Expand Down
10 changes: 5 additions & 5 deletions src/test-utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import {
} from 'apollo-client/transport/networkInterface';

import {
GraphQLResult,
Document,
ExecutionResult,
DocumentNode,
} from 'graphql';

import { print } from 'graphql-tag/printer';
Expand Down Expand Up @@ -74,20 +74,20 @@ export function mockSubscriptionNetworkInterface(

export interface ParsedRequest {
variables?: Object;
query?: Document;
query?: DocumentNode;
debugName?: string;
}

export interface MockedResponse {
request: ParsedRequest;
result?: GraphQLResult;
result?: ExecutionResult;
error?: Error;
delay?: number;
newData?: () => any;
}

export interface MockedSubscriptionResult {
result?: GraphQLResult;
result?: ExecutionResult;
error?: Error;
delay?: number;
}
Expand Down
3 changes: 0 additions & 3 deletions typings.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/// <reference path="./node_modules/typed-graphql/graphql.d.ts" />


/*
LODASH
*/
Expand Down
Loading