Skip to content

Commit

Permalink
make data proxy arguments named arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
calebmer committed Feb 28, 2017
1 parent 3c7f401 commit f2a6fc7
Show file tree
Hide file tree
Showing 6 changed files with 410 additions and 384 deletions.
24 changes: 12 additions & 12 deletions src/ApolloClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,11 +359,11 @@ export default class ApolloClient {
*
* @param variables Any variables that the GraphQL query may depend on.
*/
public readQuery<QueryType>(
public readQuery<QueryType>(config: {
query: DocumentNode,
variables?: Object,
): QueryType {
return this.initProxy().readQuery<QueryType>(query, variables);
}): QueryType {
return this.initProxy().readQuery<QueryType>(config);
}

/**
Expand Down Expand Up @@ -392,13 +392,13 @@ export default class ApolloClient {
*
* @param variables Any variables that your GraphQL fragments depend on.
*/
public readFragment<FragmentType>(
public readFragment<FragmentType>(config: {
id: string,
fragment: DocumentNode,
fragmentName?: string,
variables?: Object,
): FragmentType | null {
return this.initProxy().readFragment<FragmentType>(id, fragment, fragmentName, variables);
}): FragmentType | null {
return this.initProxy().readFragment<FragmentType>(config);
}

/**
Expand All @@ -412,12 +412,12 @@ export default class ApolloClient {
*
* @param variables Any variables that the GraphQL query may depend on.
*/
public writeQuery(
public writeQuery(config: {
data: any,
query: DocumentNode,
variables?: Object,
): void {
return this.initProxy().writeQuery(data, query, variables);
}): void {
return this.initProxy().writeQuery(config);
}

/**
Expand Down Expand Up @@ -447,14 +447,14 @@ export default class ApolloClient {
*
* @param variables Any variables that your GraphQL fragments depend on.
*/
public writeFragment(
public writeFragment(config: {
data: any,
id: string,
fragment: DocumentNode,
fragmentName?: string,
variables?: Object,
): void {
return this.initProxy().writeFragment(data, id, fragment, fragmentName, variables);
}): void {
return this.initProxy().writeFragment(config);
}

/**
Expand Down
84 changes: 60 additions & 24 deletions src/data/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,44 +16,44 @@ export interface DataProxy {
/**
* Reads a GraphQL query from the root query id.
*/
readQuery<QueryType>(
readQuery<QueryType>(config: {
query: DocumentNode,
variables?: Object,
): QueryType;
}): QueryType;

/**
* Reads a GraphQL fragment from any arbitrary id. If there are more then
* one fragments in the provided document then a `fragmentName` must be
* provided to select the correct fragment.
*/
readFragment<FragmentType>(
readFragment<FragmentType>(config: {
id: string,
fragment: DocumentNode,
fragmentName?: string,
variables?: Object,
): FragmentType | null;
}): FragmentType | null;

/**
* Writes a GraphQL query to the root query id.
*/
writeQuery(
writeQuery(config: {
data: any,
query: DocumentNode,
variables?: Object,
): void;
}): void;

/**
* Writes a GraphQL fragment to any arbitrary id. If there are more then
* one fragments in the provided document then a `fragmentName` must be
* provided to select the correct fragment.
*/
writeFragment(
writeFragment(config: {
data: any,
id: string,
fragment: DocumentNode,
fragmentName?: string,
variables?: Object,
): void;
}): void;
}

/**
Expand Down Expand Up @@ -86,10 +86,13 @@ export class ReduxDataProxy implements DataProxy {
/**
* Reads a query from the Redux state.
*/
public readQuery<QueryType>(
public readQuery<QueryType>({
query,
variables,
}: {
query: DocumentNode,
variables?: Object,
): QueryType {
}): QueryType {
return readQueryFromStore<QueryType>({
rootId: 'ROOT_QUERY',
store: getDataWithOptimisticResults(this.reduxRootSelector(this.store.getState())),
Expand All @@ -102,12 +105,17 @@ export class ReduxDataProxy implements DataProxy {
/**
* Reads a fragment from the Redux state.
*/
public readFragment<FragmentType>(
public readFragment<FragmentType>({
id,
fragment,
fragmentName,
variables,
}: {
id: string,
fragment: DocumentNode,
fragmentName?: string,
variables?: Object,
): FragmentType | null {
}): FragmentType | null {
const query = getFragmentQueryDocument(fragment, fragmentName);
const data = getDataWithOptimisticResults(this.reduxRootSelector(this.store.getState()));

Expand All @@ -129,11 +137,15 @@ export class ReduxDataProxy implements DataProxy {
/**
* Writes a query to the Redux state.
*/
public writeQuery(
public writeQuery({
data,
query,
variables,
}: {
data: any,
query: DocumentNode,
variables?: Object,
): void {
}): void {
this.store.dispatch({
type: 'APOLLO_WRITE',
writes: [{
Expand All @@ -148,13 +160,19 @@ export class ReduxDataProxy implements DataProxy {
/**
* Writes a fragment to the Redux state.
*/
public writeFragment(
public writeFragment({
data,
id,
fragment,
fragmentName,
variables,
}: {
data: any,
id: string,
fragment: DocumentNode,
fragmentName?: string,
variables?: Object,
): void {
}): void {
this.store.dispatch({
type: 'APOLLO_WRITE',
writes: [{
Expand Down Expand Up @@ -216,10 +234,13 @@ export class TransactionDataProxy implements DataProxy {
*
* Throws an error if the transaction has finished.
*/
public readQuery<QueryType>(
public readQuery<QueryType>({
query,
variables,
}: {
query: DocumentNode,
variables?: Object,
): QueryType {
}): QueryType {
this.assertNotFinished();
return readQueryFromStore<QueryType>({
rootId: 'ROOT_QUERY',
Expand All @@ -235,12 +256,17 @@ export class TransactionDataProxy implements DataProxy {
*
* Throws an error if the transaction has finished.
*/
public readFragment<FragmentType>(
public readFragment<FragmentType>({
id,
fragment,
fragmentName,
variables,
}: {
id: string,
fragment: DocumentNode,
fragmentName?: string,
variables?: Object,
): FragmentType | null {
}): FragmentType | null {
this.assertNotFinished();
const { data } = this;
const query = getFragmentQueryDocument(fragment, fragmentName);
Expand All @@ -265,11 +291,15 @@ export class TransactionDataProxy implements DataProxy {
* a write to the store at the root query id. Cannot be called after
* the transaction finishes.
*/
public writeQuery(
public writeQuery({
data,
query,
variables,
}: {
data: any,
query: DocumentNode,
variables?: Object,
): void {
}): void {
this.assertNotFinished();
this.writes.push({
rootId: 'ROOT_QUERY',
Expand All @@ -284,13 +314,19 @@ export class TransactionDataProxy implements DataProxy {
* write to the store form some fragment data at an arbitrary id. Cannot be
* called after the transaction finishes.
*/
public writeFragment(
public writeFragment({
data,
id,
fragment,
fragmentName,
variables,
}: {
data: any,
id: string,
fragment: DocumentNode,
fragmentName?: string,
variables?: Object,
): void {
}): void {
this.assertNotFinished();
this.writes.push({
rootId: id,
Expand Down
Loading

0 comments on commit f2a6fc7

Please sign in to comment.