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

POC: Spike GraphQL query management and merging strategy (DONT MERGE) #30814

Closed

Conversation

zJaaal
Copy link
Contributor

@zJaaal zJaaal commented Nov 29, 2024

Summary

This POC makes use of GraphQL Fragments in order to merge queries. Also makes use of the proposed API that we selected in the planning stage.

const data = await client.gql({
        page: {
            url: params?.slug?.join('/'),
            language: searchParams?.language_id,
            mode: 'EDIT_MODE',
            pageFragment: `
            containers {
                containerContentlets {
                    contentlets {
                        ... on Blog {
                            author {
                                firstName
                                lastName
                            }
                        }
                    }
                }
            }
        `
        },
        content: {
            blogs: `search(query: "+contentType: blog", limit: 3) {
            _map
            title
            ...on Blog {
                author {
                    title
                }
            }
        }`,
            destinations: `search(query: "+contentType: destination", limit: 3) {
            _map
        }`
        }
    });

This way the developer should only write a Fragment to extend the Page API response and also can write as much queries as they want inside the content object.

In this case all limitations, errors, query depth, cache handling and implications will be inherited naturally from how the GraphQL API works, since we are using a native way of merge queries and should not require any extra work from our side apart from exposing a simple way of using dotCMS API with GQL Queries and adapt our current architecture to make it editable inside UVE (which changes can be seen in this PR in a simple version of how it should be).

Content Editing with this POC on UVE

Screen.Recording.2024-11-29.at.3.08.43.PM-1.mov

This POC is just a proof of how this can be achieved and not a final design of how this will work or the architecture of it, we still have to make some work to make this as clean, easy and reuse as much code as we can (building the queries inside content, at least the Lucene Query, can be done with an existing API).

contentQueries: string;
}) => `
fragment DotCMSPage on DotPage {
_map
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't think we need this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, we can define the props we need.

Comment on lines +48 to +53
viewAs {
visitor {
persona {
name
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably not

page: {
url: params?.slug?.join('/'),
language: searchParams?.language_id,
mode: 'EDIT_MODE',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to control this, should be optional for them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree

Comment on lines -1 to +20
"use client";
'use client';

import WebPageContent from "./content-types/webPageContent";
import Banner from "./content-types/banner";
import Blog from "./content-types/blog";
import Activity from "./content-types/activity";
import CallToAction from "./content-types/callToAction";
import CalendarEvent from "./content-types/calendarEvent";
import Product from "./content-types/product";
import ImageComponent from "./content-types/image";
import WebPageContent from './content-types/webPageContent';
import Banner from './content-types/banner';
import Blog from './content-types/blog';
import Activity from './content-types/activity';
import CallToAction from './content-types/callToAction';
import CalendarEvent from './content-types/calendarEvent';
import Product from './content-types/product';
import ImageComponent from './content-types/image';

import Header from "./layout/header/header";
import Footer from "./layout/footer/footer";
import Navigation from "./layout/navigation";
import { usePathname, useRouter } from "next/navigation";
import { DotcmsLayout } from "@dotcms/react";
import { withExperiments } from "@dotcms/experiments";
import { CustomNoComponent } from "./content-types/empty";
import Header from './layout/header/header';
import Footer from './layout/footer/footer';
import Navigation from './layout/navigation';
import { usePathname, useRouter } from 'next/navigation';
import { DotcmsLayout } from '@dotcms/react';
import { withExperiments } from '@dotcms/experiments';
import { CustomNoComponent } from './content-types/empty';

import { usePageAsset } from "../hooks/usePageAsset";
import NotFound from "@/app/not-found";
import { usePageAsset } from '../hooks/usePageAsset';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this keep happening?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My global prettier is configured for single quotes and maybe someone else in the team uses double quotes in their IDE, the examples does not have prettier

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Spike: GraphQL Query Management and Merging Strategy
2 participants