Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

147
Views
Using static variables in a Graphql schema to avoid duplication?

Is it a good practice to use static variables in a Graphql schema on repeated schema params? like shown in the example below

const TeaserGroupParams = `{
    id: String
    workflowId: String
    headline: String
    description: String
    groupLayout: TeaserGroupLayout
    elementLayout: TeaserGroupElementLayout
    teaserElements: [TeaserElement]
    teaserDynamic: TeaserDynamic
    teaserDynamicConfigId: Int
    toplistSorting: String
    bookmarked: Boolean
    workingCopy: Workflow
    workflows: [Workflow]
    assignmentCount: Int
    assignedElements: [AssignedUnion]
    }
`;

export const TeaserGroupSchema = `

  union AssignedUnion = Article | Page

  type TeaserGroup ${TeaserGroupParams}
`;

export const TeaserGroupWorkflowSchema = `
  type TeaserGroupWorkflow ${TeaserGroupParams}
`;

Can I also have a similar approach on the client-side, to avoid duplication once more?

query GetTeaserGroup ($id: String!) {
    teaserGroup(id: $id) {
      asset {
        ... on TeaserGroup {
          id
          headline

...

        ... on TeaserGroupWorkflow {
          id
          headline
          description
          elementLayout

...

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Took from https://www.apollographql.com/docs/react/caching/cache-configuration

import { gql } from '@apollo/client';

export const CORE_COMMENT_FIELDS = gql`
  fragment CoreCommentFields on Comment {
    id
    postedBy {
      username
      displayName
    }
    createdAt
    content
  }
`;

and .. :

import { gql } from '@apollo/client';
import { CORE_COMMENT_FIELDS } from './fragments';

export const GET_POST_DETAILS = gql`
  ${CORE_COMMENT_FIELDS}
  query CommentsForPost($postId: ID!) {
    post(postId: $postId) {
      title
      body
      author
      comments {
        ...CoreCommentFields
      }
    }
  }
`;

It was a good practice, with Fragments all works as intended. Thank you Tomasz

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!