Skip to content
This repository has been archived by the owner on Jul 6, 2020. It is now read-only.

Commit

Permalink
Add populate exchange (#120)
Browse files Browse the repository at this point in the history
* Populate exchange

* Fix linting

* Add missing snapshots

* Use heler fns

* Add imports

* Add types for error codes (still not very clear)
  • Loading branch information
andyrichardson authored and kitten committed Dec 3, 2019
1 parent 2e09954 commit 36452f2
Show file tree
Hide file tree
Showing 6 changed files with 876 additions and 3 deletions.
114 changes: 114 additions & 0 deletions src/__snapshots__/populate.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`on (query w/ fragment) -> mutation mutation query matches snapshot 1`] = `
"mutation MyMutation {
addTodo {
...Todo_PopulateFragment_0
}
}
fragment Todo_PopulateFragment_0 on Todo {
...TodoFragment
}
fragment TodoFragment on Todo {
id
text
}
"
`;

exports[`on (query w/ unused fragment) -> mutation mutation query matches snapshot 1`] = `
"mutation MyMutation {
addTodo {
...Todo_PopulateFragment_0
}
}
fragment Todo_PopulateFragment_0 on Todo {
id
text
}
"
`;

exports[`on mutation mutation query matches snapshot 1`] = `
"mutation MyMutation {
addTodo {
__typename
}
}
"
`;

exports[`on query -> (mutation w/ interface return type) mutation query matches snapshot 1`] = `
"mutation MyMutation {
removeTodo {
...Todo_PopulateFragment_0
...User_PopulateFragment_0
}
}
fragment Todo_PopulateFragment_0 on Todo {
id
name
}
fragment User_PopulateFragment_0 on User {
id
text
}
"
`;

exports[`on query -> (mutation w/ union return type) mutation query matches snapshot 1`] = `
"mutation MyMutation {
updateTodo {
...User_PopulateFragment_0
...Todo_PopulateFragment_0
}
}
fragment User_PopulateFragment_0 on User {
id
text
}
fragment Todo_PopulateFragment_0 on Todo {
id
name
}
"
`;

exports[`on query -> mutation mutation query matches snapshot 1`] = `
"mutation MyMutation {
addTodo {
...Todo_PopulateFragment_0
...Todo_PopulateFragment_1
}
}
fragment Todo_PopulateFragment_0 on Todo {
id
text
creator {
id
name
}
}
fragment Todo_PopulateFragment_1 on Todo {
text
}
"
`;

exports[`on query -> teardown -> mutation mutation query matches snapshot 1`] = `
"mutation MyMutation {
addTodo {
__typename
}
}
"
`;
6 changes: 3 additions & 3 deletions src/helpers/help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// You can read more about the messages themselves in `docs/help.md`

import { Kind, ExecutableDefinitionNode, InlineFragmentNode } from 'graphql';
import { Ref } from '../types';
import { Ref, ErrorCode } from '../types';

type DebugNode = ExecutableDefinitionNode | InlineFragmentNode;

Expand Down Expand Up @@ -37,7 +37,7 @@ const getDebugOutput = (): string =>
? '\n(Caused At: ' + currentDebugStack.current.join(', ') + ')'
: '';

export const invariant = (clause: any, message: string, code: number) => {
export const invariant = (clause: any, message: string, code: ErrorCode) => {
if (!clause) {
let errorMessage = message || 'Minfied Error #' + code + '\n';
if (process.env.NODE_ENV !== 'production') {
Expand All @@ -50,7 +50,7 @@ export const invariant = (clause: any, message: string, code: number) => {
}
};

export const warn = (message: string, code: number) => {
export const warn = (message: string, code: ErrorCode) => {
if (!cache.has(message)) {
console.warn(message + getDebugOutput() + helpUrl + code);
cache.add(message);
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export * from './operations';
export * from './types';
export { Store } from './store';
export { cacheExchange } from './exchange';
export { populateExchange } from './populate';
Loading

0 comments on commit 36452f2

Please sign in to comment.