Download next.js/examples/api-routes-apollo-server/pages/api/graphql.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 844 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/examples/api-routes-apollo-server/pages/api/graphql.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/next.js/examples/api-routes-apollo-server/pages/api/graphql.ts
-
curl -L -o graphql.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/examples/api-routes-apollo-server/pages/api/graphql.ts
844 Bytes
| import { ApolloServer } from "@apollo/server"; | |
| import { startServerAndCreateNextHandler } from "@as-integrations/next"; | |
| import { makeExecutableSchema } from "@graphql-tools/schema"; | |
| import { gql } from "graphql-tag"; | |
| const typeDefs = gql` | |
| type Query { | |
| users: [User!]! | |
| user(username: String): User | |
| } | |
| type User { | |
| name: String | |
| username: String | |
| } | |
| `; | |
| const users = [ | |
| { name: "Leeroy Jenkins", username: "leeroy" }, | |
| { name: "Foo Bar", username: "foobar" }, | |
| ]; | |
| const resolvers = { | |
| Query: { | |
| users() { | |
| return users; | |
| }, | |
| user(parent, { username }) { | |
| return users.find((user) => user.username === username); | |
| }, | |
| }, | |
| }; | |
| export const schema = makeExecutableSchema({ typeDefs, resolvers }); | |
| const server = new ApolloServer({ | |
| schema, | |
| }); | |
| export default startServerAndCreateNextHandler(server); | |