Skip to content

Commit

Permalink
Merge pull request #4233 from apollographql/hwillson/graphql-updates
Browse files Browse the repository at this point in the history
Modernize `apollo-utilities` graphql transformation functionality
  • Loading branch information
hwillson authored Dec 20, 2018
2 parents a444e58 + 2d3df6e commit c04600b
Show file tree
Hide file tree
Showing 13 changed files with 333 additions and 608 deletions.
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,22 @@

## Apollo Client (vNext)

### Apollo Client (vNext)

- Apollo Client has been updated to use `graphql` 14.x as a dev dependency. <br/>
[@hwillson](https://github.com/hwillson) in [#4233](https://github.com/apollographql/apollo-client/pull/4233)

### Apollo Utilities (vNext)

- Transformation utilities have been refactored to work with `graphql` 14.x.
GraphQL AST's are no longer being directly modified. <br/>
[@hwillson](https://github.com/hwillson) in [#4233](https://github.com/apollographql/apollo-client/pull/4233)

## Apollo Client (2.4.8)

### Apollo Client (2.4.8)

- Documtation and config updates. <br/>
- Documentation and config updates. <br/>
[@justinanastos](https://github.com/justinanastos) in [#4187](https://github.com/apollographql/apollo-client/pull/4187) <br/>
[@PowerKiKi](https://github.com/PowerKiKi) in [#3693](https://github.com/apollographql/apollo-client/pull/3693) <br/>
[@nandito](https://github.com/nandito) in [#3865](https://github.com/apollographql/apollo-client/pull/3865)
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
"devDependencies": {
"@octokit/rest": "15.18.1",
"@types/benchmark": "1.0.31",
"@types/graphql": "0.12.7",
"@types/graphql": "14.0.3",
"@types/isomorphic-fetch": "0.0.34",
"@types/jest": "23.3.10",
"@types/lodash": "4.14.119",
Expand All @@ -103,7 +103,7 @@
"danger": "4.4.10",
"fetch-mock": "7.2.5",
"flow-bin": "0.89.0",
"graphql": "0.13.2",
"graphql": "14.0.2",
"graphql-tag": "2.10.0",
"isomorphic-fetch": "2.2.1",
"jest": "23.6.0",
Expand Down
10 changes: 3 additions & 7 deletions packages/apollo-cache/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,21 +71,17 @@ function selectionSetFromObj(obj: any): SelectionSetNode {
const selections: FieldNode[] = [];

Object.keys(obj).forEach(key => {
const nestedSelSet: SelectionSetNode = selectionSetFromObj(obj[key]);

const field: FieldNode = {
kind: 'Field',
name: {
kind: 'Name',
value: key,
},
selectionSet: nestedSelSet || undefined,
};

// Recurse
const nestedSelSet: SelectionSetNode = selectionSetFromObj(obj[key]);

if (nestedSelSet) {
field.selectionSet = nestedSelSet;
}

selections.push(field);
});

Expand Down
24 changes: 14 additions & 10 deletions packages/apollo-client/src/core/ObservableQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { QueryStoreValue } from '../data/queries';

export type ApolloCurrentResult<T> = {
data: T | {};
errors?: GraphQLError[];
errors?: ReadonlyArray<GraphQLError>;
loading: boolean;
networkStatus: NetworkStatus;
error?: ApolloError;
Expand Down Expand Up @@ -228,7 +228,8 @@ export class ObservableQuery<
public isDifferentFromLastResult(newResult: ApolloQueryResult<TData>) {
const { lastResultSnapshot: snapshot } = this;
return !(
snapshot && newResult &&
snapshot &&
newResult &&
snapshot.networkStatus === newResult.networkStatus &&
snapshot.stale === newResult.stale &&
isEqual(snapshot.data, newResult.data)
Expand Down Expand Up @@ -356,7 +357,9 @@ export class ObservableQuery<
// XXX the subscription variables are separate from the query variables.
// if you want to update subscription variables, right now you have to do that separately,
// and you can only do it by stopping the subscription and then subscribing again with new variables.
public subscribeToMore<TSubscriptionData = TData>(options: SubscribeToMoreOptions<TData, TVariables, TSubscriptionData>) {
public subscribeToMore<TSubscriptionData = TData>(
options: SubscribeToMoreOptions<TData, TVariables, TSubscriptionData>,
) {
const subscription = this.queryManager
.startGraphQLSubscription({
query: options.document,
Expand All @@ -366,13 +369,14 @@ export class ObservableQuery<
next: (subscriptionData: { data: TSubscriptionData }) => {
if (options.updateQuery) {
this.updateQuery((previous, { variables }) =>
(options.updateQuery as UpdateQueryFn<TData, TVariables, TSubscriptionData>)(
previous,
{
subscriptionData,
variables,
},
),
(options.updateQuery as UpdateQueryFn<
TData,
TVariables,
TSubscriptionData
>)(previous, {
subscriptionData,
variables,
}),
);
}
},
Expand Down
2 changes: 1 addition & 1 deletion packages/apollo-client/src/core/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export type PureQueryOptions = {

export type ApolloQueryResult<T> = {
data: T;
errors?: GraphQLError[];
errors?: ReadonlyArray<GraphQLError>;
loading: boolean;
networkStatus: NetworkStatus;
stale: boolean;
Expand Down
4 changes: 2 additions & 2 deletions packages/apollo-client/src/data/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export type QueryStoreValue = {
previousVariables?: Object | null;
networkStatus: NetworkStatus;
networkError?: Error | null;
graphQLErrors?: GraphQLError[];
graphQLErrors?: ReadonlyArray<GraphQLError>;
metadata: any;
};

Expand Down Expand Up @@ -78,7 +78,7 @@ export class QueryStore {
networkStatus = NetworkStatus.loading;
}

let graphQLErrors: GraphQLError[] = [];
let graphQLErrors: ReadonlyArray<GraphQLError> = [];
if (previousQuery && previousQuery.graphQLErrors) {
graphQLErrors = previousQuery.graphQLErrors;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/apollo-client/src/errors/ApolloError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const generateErrorMessage = (err: ApolloError) => {

export class ApolloError extends Error {
public message: string;
public graphQLErrors: GraphQLError[];
public graphQLErrors: ReadonlyArray<GraphQLError>;
public networkError: Error | null;

// An object that can be used to provide some additional information
Expand All @@ -48,7 +48,7 @@ export class ApolloError extends Error {
errorMessage,
extraInfo,
}: {
graphQLErrors?: GraphQLError[];
graphQLErrors?: ReadonlyArray<GraphQLError>;
networkError?: Error | null;
errorMessage?: string;
extraInfo?: any;
Expand Down
6 changes: 2 additions & 4 deletions packages/apollo-utilities/src/__tests__/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ describe('query transforms', () => {
`;
const expectedQueryStr = print(expectedQuery);

expect(expectedQueryStr).toBe(print(newQueryDoc));
expect(print(newQueryDoc)).toBe(expectedQueryStr);
});

it('should not add duplicates', () => {
Expand Down Expand Up @@ -565,7 +565,7 @@ describe('query transforms', () => {
`;
const expectedQueryStr = print(expectedQuery);

expect(expectedQueryStr).toBe(print(newQueryDoc));
expect(print(newQueryDoc)).toBe(expectedQueryStr);
});

it('should not screw up on a FragmentSpread within the query AST', () => {
Expand Down Expand Up @@ -1167,8 +1167,6 @@ describe('getDirectivesFromDocument', () => {
const expected = gql`
fragment client on ClientData {
hi @client
bye @storage
bar
}
query Mixed {
Expand Down
2 changes: 2 additions & 0 deletions packages/apollo-utilities/src/getFromAST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ string in a "gql" tag? http://docs.apollostack.com/apollo-client/core.html#gql`)
`Ambiguous GraphQL document: contains ${operations.length} operations`,
);
}

return doc;
}

export function getOperationDefinition(
Expand Down
Loading

0 comments on commit c04600b

Please sign in to comment.