Skip to content

Home for all GraphQL schema and types used in dictyBase applications

Notifications You must be signed in to change notification settings

dictyBase/dicty-graphql-schema

Repository files navigation

dicty-graphql-schema

This repository contains GraphQL schema and TypeScript types for the dictyBase API.

All schema, queries and mutations are inside the src folder. The schema folder contains the graphql schema definitions. The mutations and queries folders has the graphql documents.

Install

yarn add dictybase/dicty-graphql-schema

To install a particular version (check tags/release first)

yarn add dictyBase/dicty-graphql-schema#v1.0.0

Usage

The code generated by the graphql-codegen plugins can be used in the following ways

typescript

Generates base Typescript types which are used as base types for other plugins. Details here

typescript-operations

Generates types for graphql documents: Query, Mutation etc. Details here

typescript-react-apollo

Generated typed react hooks for every graphql opertation in the documents. For example, the following hook can be used get a list of strain from our graphql API.

import {useStrainListQuery} from "dictybase/dicty-graphql-schema"

export const MyStrainComponent = () => {
  const { data, loading, error } = useStrainListQuery({ variables: { limit }})
  ......

  return (
    <div>{data}</div>
    ....
  )
}

Details here

typed-document-node

Details here

fragment-matcher

The generated code should be used with apollo-clientv3, particularly in case of configuring cache. For example,

import { InMemoryCache } from '@apollo/client'
// generated by Fragment Matcher plugin
import {PossibleTypesResultData} from "dictybase/dicty-graphql-schema/fragment"
const cache = new InMemoryCache({ possibleTypes: PossibleTypesResultData.possibleTypes })

Details here

typescript-apollo-client-helpers

Generates fully-typed keyFields and Type-Policies for apollo-client. It can be imported like this ...

import {XXXXXXX} from "dictybase/dicty-graphql-schema/apollo-client-helpers"

Details here.

typescript-msw

Generates msw based typed mock handlers for graphql API. The handlers can be imported like this....

import {handlerxxxxx} from "dictybase/dicty-graphql-schema/mocks"

Details here

introspection

Generates a json formatted graphql introspection file saves as schema.json. Details here

document-nodes

Details here

Development using github pull request

  • Clone the repository.
  • Create a new branch (i.e. feature/new-schema).
  • Install bun
  • Run bun install
  • Complete any necessary work.
  • Run bun run --bun generat to generate code from the schema. The generated code will go in the types folder.
  • Commit all changes and create a github pull request.
  • Repeat the cycle until the work is done. When finished, merge to develop.

Release

  • If you are ready to cut a new release, merge(rebase) develop into main.
  • Install nsv.
  • Run nsv next to determine the version.
  • Then run gh release create to create a new release using the version no as a tag.