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

WIP: Evaluating Gql.tada instead of graphql-codegen #203

Closed
wants to merge 1 commit into from
Closed
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
4 changes: 3 additions & 1 deletion next/.vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@
// Tailwind intellisense also in strings
"editor.quickSuggestions": {
"strings": true
}
},
"typescript.tsdk": "node_modules/typescript/lib",
"typescript.enablePromptUseWorkspaceTsdk": true
}
2 changes: 1 addition & 1 deletion next/lib/graphql/fragments/fields.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { graphql } from "@/lib/gql";
import { graphql } from "gql.tada";

export const FRAGMENT_TEXT = graphql(`
fragment FragmentText on Text {
Expand Down
77 changes: 47 additions & 30 deletions next/lib/graphql/fragments/media.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,18 @@
import { graphql } from "@/lib/gql";
import { graphql } from "gql.tada";

export const FRAGMENT_MEDIA_UNION = graphql(`
# This fragment needs to reference ALL the other defined media fragments in this file.
# This fragment can be used in queries where a media entity type field is present.
# Graphql-codegen will then generate a type with all possible variations of media
# that we need to typecast media in the frontend.
fragment FragmentMediaUnion on MediaInterface {
__typename
id
...FragmentMediaAudio
...FragmentMediaDocument
...FragmentMediaImage
...FragmentMediaRemoteVideo
...FragmentMediaVideo
}
`);
import { FRAGMENT_FILE, FRAGMENT_IMAGE } from "./fields";

export const FRAGMENT_MEDIA_AUDIO = graphql(`
fragment FragmentMediaAudio on MediaAudio {
name
mediaAudioFile {
...FragmentFile
export const FRAGMENT_MEDIA_AUDIO = graphql(
`
fragment FragmentMediaAudio on MediaAudio {
name
mediaAudioFile {
...FragmentFile
}
}
}
`);
`,
[FRAGMENT_FILE],
);

export const FRAGMENT_MEDIA_VIDEO = graphql(`
fragment FragmentMediaVideo on MediaVideo {
Expand All @@ -43,18 +32,46 @@ export const FRAGMENT_MEDIA_DOCUMENT = graphql(`
}
`);

export const FRAGMENT_MEDIA_IMAGE = graphql(`
fragment FragmentMediaImage on MediaImage {
name
mediaImage {
...FragmentImage
export const FRAGMENT_MEDIA_IMAGE = graphql(
`
fragment FragmentMediaImage on MediaImage {
name
mediaImage {
...FragmentImage
}
}
}
`);
`,
[FRAGMENT_IMAGE],
);

export const FRAGMENT_MEDIA_REMOTE_VIDEO = graphql(`
fragment FragmentMediaRemoteVideo on MediaRemoteVideo {
name
mediaOembedVideo
}
`);

export const FRAGMENT_MEDIA_UNION = graphql(
`
# This fragment needs to reference ALL the other defined media fragments in this file.
# This fragment can be used in queries where a media entity type field is present.
# Graphql-codegen will then generate a type with all possible variations of media
# that we need to typecast media in the frontend.
fragment FragmentMediaUnion on MediaInterface {
__typename
id
...FragmentMediaAudio
...FragmentMediaDocument
...FragmentMediaImage
...FragmentMediaRemoteVideo
...FragmentMediaVideo
}
`,
[
FRAGMENT_MEDIA_AUDIO,
FRAGMENT_MEDIA_DOCUMENT,
FRAGMENT_MEDIA_IMAGE,
FRAGMENT_MEDIA_REMOTE_VIDEO,
FRAGMENT_MEDIA_VIDEO,
],
);
217 changes: 135 additions & 82 deletions next/lib/graphql/fragments/nodes.ts
Original file line number Diff line number Diff line change
@@ -1,97 +1,117 @@
import { graphql } from "@/lib/gql";
import { graphql } from "gql.tada";

export const FRAGMENT_NODE_UNION = graphql(`
fragment FragmentNodeUnion on NodeInterface {
__typename
id
title
status
path
langcode {
id
}
created {
timestamp
}
changed {
timestamp
}
metatag {
...FragmentMetaTag
}
...FragmentNodeArticle
...FragmentNodeFrontpage
...FragmentNodePage
}
`);
import {
FRAGMENT_IMAGE,
FRAGMENT_METATAG,
FRAGMENT_TEXT_SUMMARY,
} from "./fields";
import {
FRAGMENT_PARAGRAPH_ACCORDION,
FRAGMENT_PARAGRAPH_FILE_ATTACHMENTS,
FRAGMENT_PARAGRAPH_FORMATTED_TEXT,
FRAGMENT_PARAGRAPH_HERO,
FRAGMENT_PARAGRAPH_IMAGE,
FRAGMENT_PARAGRAPH_LINKS,
FRAGMENT_PARAGRAPH_LISTING_ARTICLE,
FRAGMENT_PARAGRAPH_VIDEO,
} from "./paragraphs";
import { FRAGMENT_USER } from "./users";

export const FRAGMENT_NODE_ARTICLE = graphql(`
fragment FragmentNodeArticle on NodeArticle {
excerpt
sticky
body {
...FragmentTextSummary
}
image {
...FragmentImage
}
author {
__typename
... on User {
...FragmentUser
export const FRAGMENT_NODE_ARTICLE = graphql(
`
fragment FragmentNodeArticle on NodeArticle {
excerpt
sticky
body {
...FragmentTextSummary
}
image {
...FragmentImage
}
author {
__typename
... on User {
...FragmentUser
}
}
}
}
`);
`,
[FRAGMENT_TEXT_SUMMARY, FRAGMENT_IMAGE, FRAGMENT_USER],
);

export const FRAGMENT_NODE_FRONTPAGE = graphql(`
fragment FragmentNodeFrontpage on NodeFrontpage {
contentElements {
... on ParagraphInterface {
__typename
id
# Here we include only the paragraph types that can actually be used in the field
# contentElements for this node type. Using the generated union type, we can be sure
# that all fragments we use here can actually be used.
... on NodeFrontpageContentElementsUnion {
...FragmentParagraphFormattedText
...FragmentParagraphLink
...FragmentParagraphImage
...FragmentParagraphVideo
...FragmentParagraphFileAttachments
...FragmentParagraphHero
...FragmentParagraphAccordion
...FragmentParagraphListingArticle
export const FRAGMENT_NODE_FRONTPAGE = graphql(
`
fragment FragmentNodeFrontpage on NodeFrontpage {
contentElements {
... on ParagraphInterface {
__typename
id
# Here we include only the paragraph types that can actually be used in the field
# contentElements for this node type. Using the generated union type, we can be sure
# that all fragments we use here can actually be used.
... on NodeFrontpageContentElementsUnion {
...FragmentParagraphFormattedText
...FragmentParagraphLink
...FragmentParagraphImage
...FragmentParagraphVideo
...FragmentParagraphFileAttachments
...FragmentParagraphHero
...FragmentParagraphAccordion
...FragmentParagraphListingArticle
}
}
}
}
}
`);
`,
[
FRAGMENT_PARAGRAPH_FORMATTED_TEXT,
FRAGMENT_PARAGRAPH_LINKS,
FRAGMENT_PARAGRAPH_IMAGE,
FRAGMENT_PARAGRAPH_VIDEO,
FRAGMENT_PARAGRAPH_FILE_ATTACHMENTS,
FRAGMENT_PARAGRAPH_HERO,
FRAGMENT_PARAGRAPH_ACCORDION,
FRAGMENT_PARAGRAPH_LISTING_ARTICLE,
],
);

export const FRAGMENT_NODE_PAGE = graphql(`
fragment FragmentNodePage on NodePage {
contentElements {
... on ParagraphInterface {
__typename
id
# Here we include only the paragraph types that can actually be used in the field
# contentElements for this node type. Using the generated union type, we can be sure
# that all fragments we refer to here can actually be used.
... on NodePageContentElementsUnion {
...FragmentParagraphFormattedText
...FragmentParagraphLink
...FragmentParagraphImage
...FragmentParagraphVideo
...FragmentParagraphFileAttachments
...FragmentParagraphHero
...FragmentParagraphAccordion
...FragmentParagraphListingArticle
...FragmentParagraphAccordion
export const FRAGMENT_NODE_PAGE = graphql(
`
fragment FragmentNodePage on NodePage {
contentElements {
... on ParagraphInterface {
__typename
id
# Here we include only the paragraph types that can actually be used in the field
# contentElements for this node type. Using the generated union type, we can be sure
# that all fragments we refer to here can actually be used.
... on NodePageContentElementsUnion {
...FragmentParagraphFormattedText
...FragmentParagraphLink
...FragmentParagraphImage
...FragmentParagraphVideo
...FragmentParagraphFileAttachments
...FragmentParagraphHero
...FragmentParagraphAccordion
...FragmentParagraphListingArticle
...FragmentParagraphAccordion
}
}
}
}
}
`);
`,
[
FRAGMENT_PARAGRAPH_FORMATTED_TEXT,
FRAGMENT_PARAGRAPH_LINKS,
FRAGMENT_PARAGRAPH_IMAGE,
FRAGMENT_PARAGRAPH_VIDEO,
FRAGMENT_PARAGRAPH_FILE_ATTACHMENTS,
FRAGMENT_PARAGRAPH_HERO,
FRAGMENT_PARAGRAPH_ACCORDION,
FRAGMENT_PARAGRAPH_LISTING_ARTICLE,
FRAGMENT_PARAGRAPH_ACCORDION,
],
);

export const FRAGMENT_ARTICLE_TEASER = graphql(`
fragment FragmentArticleTeaser on NodeArticle {
Expand All @@ -115,3 +135,36 @@ export const FRAGMENT_ARTICLE_TEASER = graphql(`
}
}
`);

export const FRAGMENT_NODE_UNION = graphql(
`
fragment FragmentNodeUnion on NodeInterface {
__typename
id
title
status
path
langcode {
id
}
created {
timestamp
}
changed {
timestamp
}
metatag {
...FragmentMetaTag
}
...FragmentNodeArticle
...FragmentNodeFrontpage
...FragmentNodePage
}
`,
[
FRAGMENT_METATAG,
FRAGMENT_NODE_ARTICLE,
FRAGMENT_NODE_FRONTPAGE,
FRAGMENT_NODE_PAGE,
],
);
Loading