Skip to content

Commit

Permalink
Revert "chore(apollo): upgrade apollo client dependencies"
Browse files Browse the repository at this point in the history
This reverts commit add896f.
  • Loading branch information
erikwrede committed Jan 21, 2025
1 parent da10db1 commit bde3e6f
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 18 deletions.
8 changes: 4 additions & 4 deletions packages/apollo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@
"@apollo/gateway": "2.3.3",
"@apollo/server": "4.7.4",
"@apollo/server-plugin-response-cache": "4.1.0",
"@apollo/subgraph": "2.4.9",
"@apollo/subgraph": "2.2.3",
"@as-integrations/fastify": "2.0.0",
"@nestjs/common": "10.0.5",
"@nestjs/core": "10.0.5",
"@nestjs/platform-express": "10.0.5",
"@nestjs/platform-fastify": "10.0.5",
"@nestjs/testing": "10.0.5",
"@apollo/client": "3.7.17",
"subscriptions-transport-ws": "0.11.0",
"graphql-ws": "5.14.0"
"apollo-cache-inmemory": "1.6.6",
"apollo-client": "2.6.10",
"apollo-link-ws": "1.0.20"
},
"dependencies": {
"@apollo/server-plugin-landing-page-graphql-playground": "4.0.0",
Expand Down
7 changes: 4 additions & 3 deletions packages/apollo/tests/subscriptions/compat.spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { INestApplication } from '@nestjs/common';
import { Test } from '@nestjs/testing';
import { ApolloClient, InMemoryCache } from '@apollo/client/core';
import { InMemoryCache } from 'apollo-cache-inmemory';
import ApolloClient from 'apollo-client';
import { WebSocketLink } from 'apollo-link-ws';
import { gql } from 'graphql-tag';
import { Client, createClient } from 'graphql-ws';
import { SubscriptionClient } from 'subscriptions-transport-ws';
import * as ws from 'ws';
import { AppModule } from './app/app.module';
import { pubSub } from './app/notification.resolver';
import { GraphQLWsLink } from '@apollo/client/link/subscriptions';
import { WebSocketLink } from '@apollo/client/link/ws';
import { GraphQLWsLink } from './utils/graphql-ws.link';

const subscriptionQuery = gql`
subscription TestSubscription($id: String!) {
Expand Down
12 changes: 4 additions & 8 deletions packages/apollo/tests/subscriptions/graphql-ws.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { INestApplication } from '@nestjs/common';
import { Test } from '@nestjs/testing';
import { ApolloClient, ApolloError, InMemoryCache } from '@apollo/client/core';
import { InMemoryCache } from 'apollo-cache-inmemory';
import ApolloClient, { ApolloError } from 'apollo-client';
import { gql } from 'graphql-tag';
import { Client, Context, createClient } from 'graphql-ws';
import * as ws from 'ws';
import { AppModule } from './app/app.module';
import { pubSub } from './app/notification.resolver';
import { GraphQLWsLink } from '@apollo/client/link/subscriptions';
import { GraphQLWsLink } from './utils/graphql-ws.link';
import { MalformedTokenException } from './utils/malformed-token.exception';

const subscriptionQuery = gql`
Expand Down Expand Up @@ -36,12 +37,7 @@ describe('graphql-ws protocol', () => {
},
subscriptions: {
'graphql-ws': {
onConnect: (
context: Context<
any,
{ socket: { close: (number, string) => any | boolean } }
>,
) => {
onConnect: (context: Context<any>) => {
if (!context.connectionParams.authorization) {
return context.extra.socket.close(
4000,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { INestApplication } from '@nestjs/common';
import { Test } from '@nestjs/testing';
import { ApolloClient, ApolloError, InMemoryCache } from '@apollo/client/core';
import { WebSocketLink } from '@apollo/client/link/ws';
import { SubscriptionClient } from 'subscriptions-transport-ws';
import { InMemoryCache } from 'apollo-cache-inmemory';
import ApolloClient, { ApolloError } from 'apollo-client';
import { WebSocketLink } from 'apollo-link-ws';
import { gql } from 'graphql-tag';
import { SubscriptionClient } from 'subscriptions-transport-ws';
import * as ws from 'ws';
import { AppModule } from './app/app.module';
import { pubSub } from './app/notification.resolver';
Expand Down Expand Up @@ -64,6 +65,7 @@ describe('subscriptions-transport-ws protocol', () => {
},
ws,
);

const apolloClient = new ApolloClient({
link: new WebSocketLink(wsClient),
cache: new InMemoryCache(),
Expand Down
26 changes: 26 additions & 0 deletions packages/apollo/tests/subscriptions/utils/graphql-ws.link.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { ApolloLink, Operation, FetchResult } from 'apollo-link';
import { Observable } from 'apollo-client/util/Observable';
import { print } from 'graphql';
import { Client } from 'graphql-ws';

export class GraphQLWsLink extends ApolloLink {
private client: Client;

constructor(client: Client) {
super();
this.client = client;
}

public request(operation: Operation): Observable<FetchResult> {
return new Observable((sink) => {
return this.client.subscribe<FetchResult>(
{ ...operation, query: print(operation.query) },
{
next: sink.next.bind(sink),
complete: sink.complete.bind(sink),
error: sink.error.bind(sink),
},
);
});
}
}

0 comments on commit bde3e6f

Please sign in to comment.