Skip to content
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

GraphQL as an intermediary between language SDKs #16

Open
elviskahoro opened this issue Oct 6, 2024 · 1 comment
Open

GraphQL as an intermediary between language SDKs #16

elviskahoro opened this issue Oct 6, 2024 · 1 comment

Comments

@elviskahoro
Copy link

Currently Convex has Typescript support as a first-class citizen. Been wondering whether it'd be feasible to interact with Convex through GraphQL endpoints. The intuition being that we could then streamline bootstrapping SDKs for other languages.

https://github.com/dagger/dagger does this really well!

@sujayakar
Copy link
Contributor

sujayakar commented Oct 7, 2024

hey @elviskahoro !

we currently don't have built in support for this, but one idea would be to define your own graphql API within a convex function. for example, you could wire up graphql-http to an HTTP action:

// convex/http.ts

import { httpRouter } from 'convex/server';
import { httpAction } from './_generated/server';
import { GraphQLSchema, GraphQLObjectType, GraphQLString } from 'graphql';
import { createHandler } from 'graphql-http/lib/use/fetch';

const schema = new GraphQLSchema({
  query: new GraphQLObjectType({
    name: 'Query',
    fields: {
      hello: {
        type: GraphQLString,
        resolve: () => 'world',
      },
    },
  }),
});

const handler = createHandler({ schema });

const http = httpRouter();

http.route({
  path: '/api/graphql',
  method: 'POST',
  handler: httpAction(async (ctx, req) => {
    const resp = await handler(req);    
    return resp;
  })
})

export default http;

then, it's possible to query this via an HTTP POST request:

$ curl -X POST 'https://$CONVEX_SITE_URL/api/graphql' -H "Content-Type: application/json" -d '{"query": "{ hello }"}'
{"data":{"hello":"world"}}

tagging @sshader, who had built https://github.com/sshader/graphql-convex/ to explore wiring up graphql with convex queries.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants