flesch avatar
flesch
altairClient
HTTP
Altair GraphQL Client import { altairClient } from "https://esm.town/v/flesch/altairClient"; import { graphql, GraphQLObjectType, GraphQLSchema, GraphQLString } from "https://esm.sh/graphql"; // Define the GraphQL schema const schema = new GraphQLSchema({ query: new GraphQLObjectType({ name: "Query", fields: { hello: { type: GraphQLString, resolve: () => "Hello from Val Town GraphQL API!", }, }, }), }); // Function to handle GraphQL requests async function handleGraphQLRequest(request: Request): Promise<Response> { const { query, variables } = await request.json(); const result = await graphql({ schema, source: query, variableValues: variables, }); return new Response(JSON.stringify(result), { headers: { "Content-Type": "application/json" }, }); } // HTTP handler function export default altairClient(async function(req: Request): Promise<Response> { if (req.method === "POST") { return handleGraphQLRequest(req); } else { return new Response("This endpoint only accepts POST requests for GraphQL queries.", { status: 405 }); } }); ā†‘ https://www.val.town/v/flesch/graphqlAPIEndpoint
1
1
Next
flesch-graphqlapiendpoint.web.val.run
Updated: November 4, 2024