Integration with Azure Functions
Azure Functions is a serverless environment that supports JavaScript, and GraphQL Yoga runs on it with a few lines of code.
Installation
npm i @azure/functions graphql-yoga graphqlExample
graphql.ts
import { createSchema, createYoga } from 'graphql-yoga'
import { app, InvocationContext } from '@azure/functions'
 
// The `InvocationContext` is your server context
const yoga = createYoga<InvocationContext>({
  // This is the path to your Azure function
  graphqlEndpoint: '/api/yoga',
  schema: createSchema({
    typeDefs: /* GraphQL */ `
      type Query {
        greetings: String
      }
    `,
    resolvers: {
      Query: {
        greetings: () => 'This is the `greetings` field of the root `Query` type'
      }
    }
  })
})
 
app.http('yoga', {
  methods: ['GET', 'POST'],
  authLevel: 'anonymous',
  handler: yoga
})You can also check a full example on our GitHub repository here .
Last updated on