-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Add playground example for layers (#41)
* add playground example with layers * prevent uncaught exception with empty GraphQL files * build layers playground in CI * fix tests
- Loading branch information
Showing
28 changed files
with
218 additions
and
9 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
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 +1 @@ | ||
playground/schema.graphql | ||
schema.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
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,9 @@ | ||
<template> | ||
<div> | ||
<header> | ||
<NuxtLink to="/">Base Page</NuxtLink> | ||
<NuxtLink to="/test-layer">Test Layer</NuxtLink> | ||
</header> | ||
<NuxtPage /> | ||
</div> | ||
</template> |
5 changes: 5 additions & 0 deletions
5
playground-layers/app/components/User/fragment.userLayer.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
fragment userLayer on User { | ||
id | ||
firstName | ||
lastName | ||
} |
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,15 @@ | ||
<template> | ||
<tr> | ||
<td>{{ id }}</td> | ||
<td>{{ firstName }}</td> | ||
<td>{{ lastName }}</td> | ||
</tr> | ||
</template> | ||
|
||
<script lang="ts" setup> | ||
defineProps<{ | ||
id: string | ||
firstName: string | ||
lastName: string | ||
}>() | ||
</script> |
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,18 @@ | ||
<template> | ||
<table v-if="users"> | ||
<tbody> | ||
<User v-for="user in users" v-bind="user" :key="user.id" /> | ||
</tbody> | ||
</table> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { useAsyncGraphqlQuery } from '#imports' | ||
const { data: users } = await useAsyncGraphqlQuery('usersLayer', null, { | ||
transform: (v) => v.data.users, | ||
graphqlCaching: { | ||
client: true, | ||
}, | ||
}) | ||
</script> |
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 '~/components/User/fragment.userLayer.graphql' | ||
|
||
query usersLayer { | ||
users { | ||
...userLayer | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
playground-layers/layers/test-layer/components/ComponentFromLayer.vue
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,3 @@ | ||
<template> | ||
<div>This is a component from a layer.</div> | ||
</template> |
3 changes: 3 additions & 0 deletions
3
playground-layers/layers/test-layer/components/fragment.layerData.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
fragment dataForLayer on DataForLayer { | ||
text | ||
} |
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,13 @@ | ||
import { resolve } from 'node:path' | ||
|
||
export default defineNuxtConfig({ | ||
app: { | ||
head: { | ||
title: 'Title from a layer', | ||
}, | ||
}, | ||
|
||
alias: { | ||
'#test-layer': resolve(__dirname, './'), | ||
}, | ||
}) |
7 changes: 7 additions & 0 deletions
7
playground-layers/layers/test-layer/pages/query.layerData.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#import '#test-layer/components/fragment.layerData.graphql' | ||
|
||
query layerData { | ||
dataForLayer { | ||
...dataForLayer | ||
} | ||
} |
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,17 @@ | ||
<template> | ||
<main> | ||
<div>A page from a layer.</div> | ||
|
||
<code>{{ data }}</code> | ||
</main> | ||
</template> | ||
|
||
<script lang="ts" setup> | ||
import { useAsyncGraphqlQuery } from '#imports' | ||
const { data } = await useAsyncGraphqlQuery('layerData', null, { | ||
transform: function (v) { | ||
return v.data.dataForLayer | ||
}, | ||
}) | ||
</script> |
3 changes: 3 additions & 0 deletions
3
playground-layers/layers/test-layer/server/graphqlMiddleware.serverOptions.ts
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,3 @@ | ||
import { defineGraphqlServerOptions } from './../../../../src/runtime/serverOptions/index' | ||
|
||
export default defineGraphqlServerOptions({}) |
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,43 @@ | ||
import { defineNuxtConfig } from 'nuxt/config' | ||
import graphqlMiddlewareModule, { type ModuleOptions } from './../src/module' | ||
const IS_DEV = process.env.NODE_ENV === 'development' | ||
|
||
const graphqlMiddleware: ModuleOptions = { | ||
graphqlEndpoint: 'http://localhost:4000', | ||
downloadSchema: IS_DEV, | ||
codegenConfig: {}, | ||
outputDocuments: false, | ||
schemaPath: './../schema.graphql', | ||
autoInlineFragments: false, | ||
codegenSchemaConfig: { | ||
urlSchemaOptions: { | ||
headers: { | ||
authentication: 'server-token', | ||
}, | ||
}, | ||
}, | ||
|
||
clientCache: { | ||
enabled: true, | ||
}, | ||
|
||
enableFileUploads: false, | ||
} | ||
|
||
export default defineNuxtConfig({ | ||
modules: [graphqlMiddlewareModule as any], | ||
graphqlMiddleware, | ||
ssr: true, | ||
|
||
extends: ['./layers/test-layer'], | ||
|
||
imports: { | ||
autoImport: false, | ||
}, | ||
|
||
future: { | ||
compatibilityVersion: 4, | ||
}, | ||
|
||
compatibilityDate: '2024-09-14', | ||
}) |
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,4 @@ | ||
{ | ||
"private": true, | ||
"name": "nuxt-graphql-middleware-playground-layers" | ||
} |
12 changes: 12 additions & 0 deletions
12
playground-layers/server/graphqlMiddleware.serverOptions.ts
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 @@ | ||
import { defineGraphqlServerOptions } from './../../src/runtime/serverOptions/index' | ||
|
||
export default defineGraphqlServerOptions({ | ||
serverFetchOptions: function (event, _operation, operationName) { | ||
const headers: Record<string, any> = { | ||
'x-nuxt-header-server': 'Value from server', | ||
authentication: 'server-token', | ||
'x-apollo-operation-name': operationName, | ||
} | ||
return { headers } | ||
}, | ||
}) |
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,3 @@ | ||
{ | ||
"extends": "../.nuxt/tsconfig.server.json" | ||
} |
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,3 @@ | ||
{ | ||
"extends": "./.nuxt/tsconfig.json" | ||
} |
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
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
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