-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
example needed for adding GraphQLLiveDirective to schema using graphql-tools and using subscription in @n1ru4l/socket-io-graphql-server #495
Comments
Regarding the
|
Hey @goodnewso, could you provide some feedback on whether the information above could solve your issues? |
I will give an update on that soon. please |
The help was ok I will try my best to highlight the possible issues am having. but first I will want to say thank you for the assistance. I had some serious issues with my system just got it fixed.
I think some simple examples and documentation for both client and servers will ease the ground query, mutation, subscription and, live query. but thanks for the help so far. |
Introspection is not necessarily tied to the GraphQL server, but rather to the execution engine the server is using. "Introspection" is just another GraphQL query that is executed against the GraphQL schema. See https://github.com/graphql/graphql-js/blob/7f40198a080ab3ea5ff3e1ecc9bf7ade130ec1bf/src/utilities/getIntrospectionQuery.js#L25 So GraphiQL or GraphQL Playground are simply executing an introspection query against the configured endpoint schema. In GraphiQL you can pass a You can simply pass it to your GraphiQL instance https://github.com/n1ru4l/graphql-bleeding-edge-playground/blob/90c1d1c089b95578fd5d45a1564ff32747fcb977/src/dev/GraphiQL.tsx#L210-L212 In general, https://github.com/n1ru4l/graphql-bleeding-edge-playground shows how you can set up GraphiQL as a development-only route within create-react-app (and it should be applicable to any other setup).
It depends on your use case. If you don't need to scale horizontally and only have one instance of your GraphQL server running you don't need something like Redis. dungeon-revealer for example is an isolated service that uses SQLite and does not need any external services/databases/scaling with minimum traffic. So in that case having an in-memory PubSub is perfectly fine. The highest load I ever had on an instance at the same time is 10 users. You might re-evaluate based on your concurrent user count/load. However, nobody is stopping you from using https://github.com/apollographql/graphql-subscriptions or https://github.com/davidyaha/graphql-redis-subscriptions TBH I think their naming is very misleading as the packages CAN be used with any other library that can benefit from pub subs wrapped in AsyncIterables.
It is possible to do authentication via a mutation. For that, you would however have to not use the lazy socket authentication at all. The implementation could look similar to this: // we use a weak map to avoid memory leaks
// so once a socket disconnects the value is purged from the map here
const authenticatedSockets = new WeakMap();
registerSocketIOGraphQLServer({
socketServer,
getParameter: ({ socket }) => ({
graphQLExecutionParameter: {
schema,
rootValue,
contextValue: {
// this is the socket that executes the operation
socket,
// a global lookup map of the authenticated sockets
authenticatedSockets,
// some auth service that is used for getting the user data for given credentials
authService
}
}
})
}); And the given resolvers (I picked a resolver map graphql-tools style), you can use whatever approach you prefer. const Mutation = {
authenticate: (_, args, context) => {
const userInfo = context.authService(args.credentials);
if (userInfo) {
authenticatedSockets.set(context.socket, userInfo);
}
},
doSomething: (_, args, context) => {
const userInfo = context.authenticatedSockets.get(context.socket);
if (!userInfo) {
throw new Error("Not authenticated :(");
}
if (!userInfo.isAdmin) {
throw new Error("Insufficient permissions :(");
}
}
}; |
Wonderful |
The directive usage with graphql-tools is now documented over here: https://github.com/n1ru4l/graphql-live-query/blob/main/packages/graphql-live-query/README.md#graphqllivedirective GraphiQL fetcher setup is documented here: https://github.com/n1ru4l/graphql-live-query/blob/main/packages/socket-io-graphql-client/README.md#graphiql-fetcher |
If I may suggest, one more tool should also be documented which is Graphql Code Generator. |
Why should it be documented? GraphQL code generator is a tool unrelated to graphql-live-query. |
sorry, i was referring to @n1ru4l/socket-io-graphql-server not graphql-live-query. |
@n1ru4l/socket-io-graphql-server does not use graphql-codegen. I think all open questions here are answered, thus I will close this issue. If you have additional questions please open a new discussion. |
am using graphql-tools to build my schema with makeExcutableSchema but when GraphQLLiveDirective is added to the schema using the schema directives I get this error.
this is a portion of my code
schema.ts
and index.ts
secondly @n1ru4l/socket-io-graphql-server does not export pubsub. so is there an example guy cause the todo app does not have an example of subscription. but in the readme it says
A layer for serving a GraphQL schema via a socket.io server. Supports Queries, Mutations, Subscriptions and Live Queries.
so how is the subscription suppose to work without pubsub over socket.io.
am I missing something. please help
The text was updated successfully, but these errors were encountered: