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

Chore/graphql fragments #641

Draft
wants to merge 6 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
3 changes: 1 addition & 2 deletions netlify.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
[build]
command = "npm run build"
command = "NODE_ENV=production npm run build"

[build.environment]
NODE_ENV = "production"
NPM_CONFIG_AUDIT = "false"
NPM_CONFIG_FUND = "false"
NPM_FLAGS = "--ignore-scripts"
Expand Down
18 changes: 17 additions & 1 deletion nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { defineNuxtConfig } from 'nuxt/config';
import { writeFile, mkdir } from 'node:fs/promises';
import graphqlLoader from 'vite-plugin-graphql-loader'
import { default as nuxtIcons } from 'nuxt-icons';
import { default as plausible } from '@nuxtjs/plausible';
import { fetchTranslations } from './src/scripts/fetch-translations';
Expand All @@ -17,6 +18,12 @@ export default defineNuxtConfig({
'@/components/app-core/index.css',
],
nitro: {
esbuild: {
options: {
// allow graphql loader to use async/await in root
target: 'esnext',
}
},
prerender: {
crawlLinks: false
}
Expand Down Expand Up @@ -65,6 +72,15 @@ export default defineNuxtConfig({
}),
])
// hook expects a promise with no return data
.then(() => {}),
.then(() => { }),
},
vite: {
build: {
// allow graphql loader to use async/await in root
target: 'esnext',
},
plugins: [
graphqlLoader()
]
}
});
37 changes: 36 additions & 1 deletion package-lock.json

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

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"datocms-listen": "^0.1.14",
"datocms-structured-text-utils": "^2.0.4",
"dayjs": "^1.11.7",
"graphql": "^16.6.0",
"nuxt": "^3.4.3",
"nuxt-icons": "^3.2.1",
"prismjs": "^1.29.0",
Expand All @@ -27,7 +28,8 @@
"eslint": "^8.39.0",
"eslint-plugin-vue": "^9.12.0",
"husky": "^8.0.3",
"nano-staged": "^0.8.0"
"nano-staged": "^0.8.0",
"vite-plugin-graphql-loader": "^2.0.0"
},
"engines": {
"node": ">=18"
Expand Down
13 changes: 13 additions & 0 deletions src/components/image-card-grid/image-card-grid.fragment.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
fragment ImageCardGridFragment on SectionImageCardGridRecord {
title
items {
id
title
body {
value
}
image {
...image
}
}
}
4 changes: 3 additions & 1 deletion src/composables/useFetchContent.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { print } from 'graphql/language/printer';
import { datocmsFetch } from '../lib/datocms-fetch.ts';
import { datocmsEnvironment } from '../constants.mjs';

export async function useFetchContent({ key = null, query, variables }) {
export async function useFetchContent({ key = null, query: queryDocument, variables }) {
const query = print(queryDocument)
const runtimeConfig = useRuntimeConfig();
const route = useRoute();
const data = ref(null);
Expand Down
2 changes: 1 addition & 1 deletion src/error.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

<script setup>
const { $i18n } = useNuxtApp();
import query from './error.query.graphql?raw';
import query from './error.query.graphql';

const { data } = await useFetchContent({
key: 'ErrorPage',
Expand Down
2 changes: 1 addition & 1 deletion src/layouts/default.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

<script setup>
const { $i18n } = useNuxtApp();
import query from './default.query.graphql?raw';
import query from './default.query.graphql';
const { afterEach } = useRouter();
const skipLink = ref(null);
const mobileMenuIsOpen = ref(false);
Expand Down
14 changes: 3 additions & 11 deletions src/pages/[language]/[slug]/index.query.graphql
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# import '../../../components/image-card-grid/image-card-grid.fragment.graphql'

query LandingPage($locale: SiteLocale, $slug: String) {
page: landingPage(locale: $locale, filter: {slug: {eq: $slug}}) {
title
Expand Down Expand Up @@ -101,17 +103,7 @@ query LandingPage($locale: SiteLocale, $slug: String) {
}
}
... on SectionImageCardGridRecord {
title
items {
id
title
body {
value
}
image {
...image
}
}
...ImageCardGridFragment
}
... on SectionJobsListRecord {
id
Expand Down
2 changes: 1 addition & 1 deletion src/pages/[language]/[slug]/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
</template>

<script setup>
import query from './index.query.graphql?raw';
import query from './index.query.graphql';

const { params } = useRoute();
const { data } = await useFetchContent({
Expand Down
4 changes: 2 additions & 2 deletions src/pages/[language]/about-us/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
</template>

<script setup>
import query from './index.query.graphql?raw';
import query from './index.query.graphql';
const { params } = useRoute();

const { data } = await useFetchContent({
Expand Down Expand Up @@ -277,4 +277,4 @@
margin-right: var(--spacing-medium);
}
}
</style>
</style>
2 changes: 1 addition & 1 deletion src/pages/[language]/blog/[slug]/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@
</template>

<script setup>
import query from './index.query.graphql?raw';
import query from './index.query.graphql';
import prismjs from 'prismjs';
import('prismjs/components/prism-graphql');
import('prismjs/components/prism-rust');
Expand Down
2 changes: 1 addition & 1 deletion src/pages/[language]/blog/page/[page].vue
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
</template>

<script setup>
import query from './index.query.graphql?raw';
import query from './index.query.graphql';

// If you change this, also change it in fetch-routes.ts
const PER_PAGE = 20;
Expand Down
2 changes: 1 addition & 1 deletion src/pages/[language]/cases/[slug]/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@
</template>

<script setup>
import query from './index.query.graphql?raw';
import query from './index.query.graphql';

const { params } = useRoute();

Expand Down
2 changes: 1 addition & 1 deletion src/pages/[language]/cases/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
</template>

<script setup>
import query from './index.query.graphql?raw';
import query from './index.query.graphql';

const { params } = useRoute();

Expand Down
2 changes: 1 addition & 1 deletion src/pages/[language]/contact/[slug]/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
</template>

<script setup>
import query from './index.query.graphql?raw';
import query from './index.query.graphql';

const { params } = useRoute();
const { data } = await useFetchContent({
Expand Down
2 changes: 1 addition & 1 deletion src/pages/[language]/contact/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
</template>

<script setup>
import query from './index.query.graphql?raw';
import query from './index.query.graphql';

const { params } = useRoute();
const { data } = await useFetchContent({
Expand Down
2 changes: 1 addition & 1 deletion src/pages/[language]/energy-first/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@
</template>

<script setup>
import query from './index.query.graphql?raw';
import query from './index.query.graphql';

const { params } = useRoute();

Expand Down
2 changes: 1 addition & 1 deletion src/pages/[language]/events/[slug]/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
</template>

<script setup>
import query from './index.query.graphql?raw';
import query from './index.query.graphql';
import formatDate from '../../../../lib/format-date';

const { params } = useRoute();
Expand Down
2 changes: 1 addition & 1 deletion src/pages/[language]/events/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
</template>

<script setup>
import query from './index.query.graphql?raw';
import query from './index.query.graphql';

const { params } = useRoute();
const { data } = await useFetchContent({
Expand Down
2 changes: 1 addition & 1 deletion src/pages/[language]/faq/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
</template>

<script setup>
import query from './index.query.graphql?raw';
import query from './index.query.graphql';

const { params } = useRoute();

Expand Down
2 changes: 1 addition & 1 deletion src/pages/[language]/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
</template>

<script setup>
import query from './index.query.graphql?raw';
import query from './index.query.graphql';
import getSelfTypingTextInterval from '~/lib/get-self-typing-text-interval'

const { params } = useRoute();
Expand Down
2 changes: 1 addition & 1 deletion src/pages/[language]/jobs/[slug]/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
</template>

<script setup>
import query from './index.query.graphql?raw';
import query from './index.query.graphql';

const { params } = useRoute();

Expand Down
2 changes: 1 addition & 1 deletion src/pages/[language]/jobs/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</template>

<script setup>
import query from './index.query.graphql?raw';
import query from './index.query.graphql';

const { params } = useRoute();

Expand Down
2 changes: 1 addition & 1 deletion src/pages/[language]/lustrum/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
</template>

<script setup>
import query from './index.query.graphql?raw';
import query from './index.query.graphql';

const { params } = useRoute();

Expand Down
2 changes: 1 addition & 1 deletion src/pages/[language]/services/[slug]/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
</template>

<script setup>
import query from './index.query.graphql?raw';
import query from './index.query.graphql';
const { $localeUrl } = useNuxtApp();

const { params } = useRoute();
Expand Down
2 changes: 1 addition & 1 deletion src/pages/[language]/services/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
</template>

<script setup>
import query from './index.query.graphql?raw';
import query from './index.query.graphql';

const { params } = useRoute();

Expand Down
4 changes: 2 additions & 2 deletions src/pages/[language]/team/[slug]/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@

<script setup>
import formatDate from '../../../../lib/format-date';
import personQuery from './index.person.graphql?raw';
import blogPostsQuery from './index.blogPosts.graphql?raw';
import personQuery from './index.person.graphql';
import blogPostsQuery from './index.blogPosts.graphql';

const route = useRoute()

Expand Down
2 changes: 1 addition & 1 deletion src/pages/[language]/work-at/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
</template>

<script setup>
import query from './index.query.graphql?raw';
import query from './index.query.graphql';

const { params } = useRoute();
const { data } = await useFetchContent({
Expand Down