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

Add populate exchange #120

Merged
merged 6 commits into from
Dec 3, 2019
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
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