Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

150
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda