Functions:parseToGqlFragment - bettyblocks/cli GitHub Wiki

Parse to GQL Fragment

The parseToGqlFragment returns a Gql fragment based on the PropertyMap option which can be used to query a record. The id for the record is also returned in the fragment, so you won't have to specify the id in the query. This function expects the value of the PropertyMap option and a model name and will return an object containing the information for the fragment. The returned fragment can then be used to create a query to fetch all the fields that were passed in the PropertyMap.

Example:

// PropertyMap option
const propertyMap = [
  {
    key: [
      {
        name: 'firstName',
        kind: 'STRING',
      },
    ],
    value: 'John',
  },
  {
    key: [
      {
        name: 'lastName',
        kind: 'STRING',
      },
    ],
    value: 'Doe',
  },
];

// Model option
const modelName = 'Task'

const { name, gql: fragmentGql } = await parseToGqlFragment({
  propertyMap,
  modelName,
});

const query = `
  ${fragmentGql}
  query($where: ${modelName}FilterInput) {
    ${queryName}(where: $where) {
      ...${name}
    }
  }
`;

await gql(query);