-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
144f6c8
commit f711ee5
Showing
21 changed files
with
3,195 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,5 @@ node_modules | |
.nitro | ||
.cache | ||
.output | ||
.env | ||
.env | ||
generated |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,7 @@ | ||
<template> | ||
<div> | ||
<h1> | ||
Nuxt 3 Template | ||
</h1> | ||
<sub> | ||
A simple app about planets. | ||
</sub> | ||
<h1>Nuxt 3 Template</h1> | ||
<sub> A simple app about cars. </sub> | ||
<NuxtPage /> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
documents: graphql/**/*.gql | ||
generates: | ||
generated/schema.d.ts: | ||
plugins: | ||
- typescript | ||
generated/operations.ts: | ||
config: | ||
documentMode: documentNode | ||
plugins: | ||
- typescript | ||
- typescript-operations | ||
- typescript-vue-apollo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Docs for Nuxt 3 Template | ||
|
||
Yo, this is the docs. | ||
|
||
- [References](references.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# References | ||
|
||
Some damn good code thingies I found over the course of this project. | ||
|
||
## Examples | ||
|
||
- [newbeea/nuxt3-apollo-starter](https://github.com/newbeea/nuxt3-apollo-starter) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
query Car($carInput: CarInput!) { | ||
car(carInput: $carInput) { | ||
id | ||
brand | ||
model | ||
year | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,18 @@ | ||
import { defineNuxtConfig } from 'nuxt'; | ||
import { defineNuxtConfig } from 'nuxt3'; | ||
|
||
// https://v3.nuxtjs.org/api/configuration/nuxt.config | ||
export default defineNuxtConfig({}); | ||
export default defineNuxtConfig({ | ||
build: { | ||
transpile: ['graphql'], | ||
}, | ||
buildModules: ['@nuxt3/graphql-codegen-module', '@nuxt3/apollo-module'], | ||
graphqlCodegen: { | ||
// TODO: Move to env var | ||
schema: ['http://localhost:3000/api/graphql'], | ||
}, | ||
apollo: { | ||
default: { | ||
uri: process.env.URL ? `${process.env.URL}/api/graphql` : 'http://localhost:3000/api/graphql', | ||
}, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<script setup lang="ts"> | ||
// TODO: Why do I need to define this? | ||
import { useCarQuery } from '~/generated/operations'; | ||
const route = useRoute(); | ||
const { result, loading, error } = useCarQuery({ carInput: { id: route.params.id } }); | ||
const car = result?.value?.car; | ||
/* | ||
definePageMeta({ | ||
title: car ? `Car with id ${car.id}` : '...', | ||
}); | ||
*/ | ||
</script> | ||
|
||
<template> | ||
<div v-if="loading"> | ||
<span> Loading... </span> | ||
</div> | ||
<div v-else-if="error"> | ||
<span> Error: {{ error }} </span> | ||
</div> | ||
<div v-else-if="car"> | ||
<h2>Car with id {{ car.id }}</h2> | ||
<div> | ||
<strong> Brand: </strong> | ||
<span> | ||
{{ car.brand }} | ||
</span> | ||
</div> | ||
<div> | ||
<strong> Model: </strong> | ||
<span> | ||
{{ car.model }} | ||
</span> | ||
</div> | ||
<div> | ||
<strong> Year: </strong> | ||
<span> | ||
{{ car.year }} | ||
</span> | ||
</div> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,17 @@ | ||
<script setup> | ||
definePageMeta({ | ||
title: 'Yao, welcome m8' | ||
}) | ||
title: 'Yao, welcome m8', | ||
}); | ||
</script> | ||
|
||
<template> | ||
<h2> | ||
Yao, welcome m8 | ||
</h2> | ||
<div> | ||
<h2>Yao, welcome m8</h2> | ||
<div> | ||
<NuxtLink to="/car/1"> Go to car with id '1' </NuxtLink> | ||
</div> | ||
<div> | ||
<NuxtLink to="/car/2"> Go to car with id '2' </NuxtLink> | ||
</div> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import * as Reflect from 'reflect-metadata'; | ||
import { buildSchemaSync } from 'type-graphql'; | ||
import resolvers from '../graphql'; | ||
import ApolloServer from '../graphql/apollo-server'; | ||
|
||
let schema; | ||
|
||
if (Reflect) { | ||
schema = buildSchemaSync({ | ||
resolvers, | ||
}); | ||
} else { | ||
throw new Error('No reflect-metadata polyfill'); | ||
} | ||
|
||
const apolloServer = new ApolloServer({ | ||
schema, | ||
}); | ||
|
||
apolloServer.start(); | ||
const handler = apolloServer.createHandler(); | ||
|
||
export default handler; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const startAt = Date.now(); | ||
let count = 0; | ||
|
||
export default () => ({ | ||
pageview: count++, | ||
startAt, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import type { IncomingMessage, ServerResponse } from 'http'; | ||
import { useBody, useQuery } from 'h3'; | ||
import type { GraphQLOptions } from 'apollo-server-core'; | ||
import { ApolloServerBase, convertNodeHttpToRequest, runHttpQuery } from 'apollo-server-core'; | ||
|
||
// TODO: Turn this into makeApolloServer() | ||
export class ApolloServer extends ApolloServerBase { | ||
async createGraphQLServerOptions(request?: IncomingMessage, reply?: ServerResponse): Promise<GraphQLOptions> { | ||
return this.graphQLServerOptions({ request, reply }); | ||
} | ||
|
||
createHandler() { | ||
return async function (req: IncomingMessage, res: ServerResponse) { | ||
const options = await this.createGraphQLServerOptions(req, res); | ||
try { | ||
const { graphqlResponse, responseInit } = await runHttpQuery([], { | ||
method: req.method || 'GET', | ||
options, | ||
query: req.method === 'POST' ? await useBody(req) : await useQuery(req), | ||
request: convertNodeHttpToRequest(req), | ||
}); | ||
if (responseInit.headers) { | ||
for (const [name, value] of Object.entries<string>(responseInit.headers)) { | ||
res.setHeader(name, value); | ||
} | ||
} | ||
res.end(graphqlResponse); | ||
} catch (error) { | ||
if (error.headers) { | ||
for (const [name, value] of Object.entries<string>(error.headers)) { | ||
res.setHeader(name, value); | ||
} | ||
} | ||
res.statusCode = error.statusCode; | ||
res.end(error.message); | ||
} | ||
}.bind(this); | ||
} | ||
} | ||
|
||
export default ApolloServer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { Resolver, Query, Arg } from 'type-graphql'; | ||
import { Car, CarInput } from './schema'; | ||
|
||
// TODO: Move mock data | ||
const carData = [ | ||
{ | ||
id: '1', | ||
brand: 'Toyota', | ||
model: 'Camri', | ||
year: 2006, | ||
}, | ||
{ | ||
id: '2', | ||
brand: 'Fort', | ||
model: 'F-150', | ||
year: 2012, | ||
}, | ||
]; | ||
|
||
@Resolver() | ||
export default class CarResolver { | ||
@Query(() => Car) | ||
car(@Arg('carInput', () => CarInput) carInput: CarInput) { | ||
return carData.find(car => car.id === carInput.id); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { Field, InputType, ObjectType } from 'type-graphql'; | ||
|
||
@InputType() | ||
export class CarInput { | ||
@Field(() => String) | ||
id: string; | ||
} | ||
|
||
@ObjectType() | ||
export class Car { | ||
@Field(() => String) | ||
id: string; | ||
|
||
@Field(() => String) | ||
brand: string; | ||
|
||
@Field(() => String) | ||
model: string; | ||
|
||
@Field(() => Number) | ||
year: number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import type { NonEmptyArray } from 'type-graphql'; | ||
import car from './cars/car.resolver'; | ||
|
||
// eslint-disable-next-line @typescript-eslint/ban-types | ||
const resolvers: NonEmptyArray<Function> = [car]; | ||
|
||
export default resolvers; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
{ | ||
"extends": "./.nuxt/tsconfig.json" | ||
"extends": "./.nuxt/tsconfig.json", | ||
"compilerOptions": { | ||
"experimentalDecorators": true | ||
} | ||
} |
Oops, something went wrong.