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

try: graphql as serverless function #36

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
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
7 changes: 7 additions & 0 deletions api/Articles/host.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"version": "2.0",
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[2.*, 3.0.0)"
}
}
15 changes: 7 additions & 8 deletions api/Articles/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
var jsonData = require('../generate');

module.exports = async function (context, req) {
const byId = (req.query.id);
context.res = {
// status: 200, /* Defaults to 200 */
body: byId ? [jsonData().articles[byId]] : jsonData().articles
};
var jsonData = require('../generate');

module.exports = async function (context, req) {
const byId = (req.query.id);
context.res = {
body: byId ? [jsonData().articles[byId]] : jsonData().articles
};
}
20 changes: 20 additions & 0 deletions api/graphql/function.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"bindings": [
{
"authLevel": "anonymous",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": [
"get",
"post",
"options"
]
},
{
"type": "http",
"direction": "out",
"name": "$return"
}
]
}
7 changes: 7 additions & 0 deletions api/graphql/host.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"version": "2.0",
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[1.*, 2.0.0)"
}
}
27 changes: 27 additions & 0 deletions api/graphql/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const { gql, ApolloServer } = require("apollo-server-azure-functions");

// Construct a schema, using GraphQL schema language
const typeDefs = gql`
type Query {
hello: String
}
`;

// A map of functions which return data for the schema.
const resolvers = {
Query: {
hello: () => "world"
}
};

const server = new ApolloServer({ typeDefs, resolvers, debug: true, playground: true });

module.exports = server.createHandler({
cors: {
origin: [
'https://studio.apollographql.com',
],
methods: ['GET', 'POST', 'OPTIONS'],
credentials: true,
},
});
3 changes: 3 additions & 0 deletions api/graphql/sample.dat
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "Azure"
}
Loading