-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add RSocketApolloGraphlQLPlugin (apollographql/apollo-server#6264)
- Loading branch information
Showing
7 changed files
with
6,257 additions
and
6,366 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
0 silly argv { | ||
0 silly argv _: [ 'run' ], | ||
0 silly argv lernaVersion: '4.0.0', | ||
0 silly argv '$0': 'node_modules\\lerna\\cli.js', | ||
0 silly argv script: 'yarn' | ||
0 silly argv } | ||
1 notice cli v4.0.0 | ||
2 verbose rootPath C:\dev\kevin\rsocket-js | ||
3 info versioning independent | ||
4 error Error: Invalid package name "apollo-server-plugin-base ": name cannot contain leading or trailing spaces; name can only contain URL-friendly characters | ||
4 error at invalidPackageName (C:\dev\kevin\rsocket-js\node_modules\npm-package-arg\npa.js:84:15) | ||
4 error at Result.setName (C:\dev\kevin\rsocket-js\node_modules\npm-package-arg\npa.js:119:11) | ||
4 error at new Result (C:\dev\kevin\rsocket-js\node_modules\npm-package-arg\npa.js:110:10) | ||
4 error at Function.resolve (C:\dev\kevin\rsocket-js\node_modules\npm-package-arg\npa.js:54:15) | ||
4 error at C:\dev\kevin\rsocket-js\node_modules\@lerna\package-graph\index.js:66:30 | ||
4 error at Array.forEach (<anonymous>) | ||
4 error at C:\dev\kevin\rsocket-js\node_modules\@lerna\package-graph\index.js:60:38 | ||
4 error at Map.forEach (<anonymous>) | ||
4 error at new PackageGraph (C:\dev\kevin\rsocket-js\node_modules\@lerna\package-graph\index.js:49:10) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
packages/rsocket-graphql-apollo-server/src/RSocketApolloGraphlQLPlugin.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { | ||
ApolloServerPlugin, | ||
BaseContext, | ||
GraphQLServerListener, | ||
GraphQLServiceContext, | ||
} from "apollo-server-plugin-base"; | ||
import { RSocket } from "rsocket-core"; | ||
import { RSocketApolloServer } from "./RSocketApolloServer"; | ||
|
||
type RSocketApolloGraphlQLPluginOptions = { | ||
apolloServer?: RSocketApolloServer; | ||
makeRSocketServer: ({ handler }: { handler: Partial<RSocket> }) => any; | ||
}; | ||
|
||
export class RSocketApolloGraphlQLPlugin<TContext extends BaseContext> | ||
implements ApolloServerPlugin<TContext> | ||
{ | ||
private apolloServer: RSocketApolloServer; | ||
constructor(private options: RSocketApolloGraphlQLPluginOptions) {} | ||
|
||
async serverWillStart( | ||
service: GraphQLServiceContext | ||
): Promise<GraphQLServerListener | void> { | ||
if (!this.apolloServer) { | ||
throw new Error( | ||
"serverWillStart called without valid apolloServer reference. Did you forget to call setApolloServer?" | ||
); | ||
} | ||
const handler = this.apolloServer.getHandler(); | ||
let rSocketServer = this.options.makeRSocketServer({ handler }); | ||
let closeable = await rSocketServer.bind(); | ||
return { | ||
async drainServer() { | ||
closeable.close(); | ||
}, | ||
}; | ||
} | ||
|
||
setApolloServer(apolloServer: RSocketApolloServer) { | ||
this.apolloServer = apolloServer; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export { ApolloServer } from "./ApolloServer"; | ||
export { RSocketApolloServer } from "./RSocketApolloServer"; |
Oops, something went wrong.