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

Update Azure Example #3355

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion e2e/tests/azure-function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export const azureFunctionDeployment: DeploymentConfiguration<{
],
http20Enabled: true,
httpLoggingEnabled: true,
linuxFxVersion: 'node|18',
linuxFxVersion: 'node|20',
},
},
{
Expand Down
6 changes: 3 additions & 3 deletions e2e/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,14 @@ export async function assertGraphiQL(endpoint: string) {
},
});

const html = await response.text();

if (response.status !== 200) {
console.warn(`⚠️ Invalid GraphiQL status code:`, response.status);
console.warn(`⚠️ Invalid GraphiQL status code:`, response.status, ', body:', html);

throw new Error(`Failed to locate GraphiQL: invalid status code (${response.status})`);
}

const html = await response.text();

if (!html.includes('<title>Yoga GraphiQL</title>')) {
console.warn(`⚠️ Invalid GraphiQL body:`, html);

Expand Down
3 changes: 2 additions & 1 deletion examples/azure-function/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ async function main() {
minify: false,
bundle: true,
platform: 'node',
target: 'node14',
target: 'node18',
external: ['@azure/functions-core'],
});

writeFileSync(
Expand Down
2 changes: 1 addition & 1 deletion examples/azure-function/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"graphql-yoga": "workspace:*"
},
"devDependencies": {
"@azure/functions": "4.0.0",
"@azure/functions": "4.5.0",
"esbuild": "0.17.19",
"tslib": "2.6.3",
"typescript": "5.5.3"
Expand Down
66 changes: 19 additions & 47 deletions examples/azure-function/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,51 +1,23 @@
import { createSchema, createYoga } from 'graphql-yoga';
import { AzureFunction, Context, HttpRequest } from '@azure/functions';
import { app, InvocationContext } from '@azure/functions';

const httpTrigger: AzureFunction = async function (
context: Context,
req: HttpRequest,
): Promise<void> {
const app = createYoga({
logging: {
debug: context.log.verbose,
error: context.log.error,
info: context.log.info,
warn: context.log.warn,
},
graphqlEndpoint: '/api/yoga',
schema: createSchema({
typeDefs: /* GraphQL */ `
type Query {
greetings: String
}
`,
resolvers: {
Query: {
greetings: () => 'This is the `greetings` field of the root `Query` type',
},
const yoga = createYoga<InvocationContext>({
graphqlEndpoint: '/api/yoga',
schema: createSchema({
typeDefs: /* GraphQL */ `
type Query {
greetings: String
}
`,
resolvers: {
Query: {
greetings: () => 'This is the `greetings` field of the root `Query` type',
},
}),
});
context.log('HTTP trigger function processed a request.');

const response = await app.fetch(req.url, {
method: req.method?.toString(),
body: req.rawBody,
headers: req.headers,
});

const headersObj = Object.fromEntries(response.headers.entries());

context.log('GraphQL Yoga response headers:', headersObj);

const responseText = await response.text();
context.log('GraphQL Yoga response text:', responseText);

context.res = {
status: response.status,
body: responseText,
headers: headersObj,
};
};
},
}),
});

export default httpTrigger;
app.http('yoga', {
method: ['GET', 'POST'],
handler: yoga,
});
17 changes: 12 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading