Auto-generate the graphQL query to cover all fields

Note that this issue has low priority.

As a frontend developer, I want the whole directus database to be exposed as a strongly typed object in my editor So that my local language server can give me suggestions and make sure my component types match the latest upstream data-model.

As a frontend developer, I don't want to mirror fields in the upstream database manually Because that will inevitably lead to unpleasant errors and omissions.

  • Auto-generate the graphQL query in src/utils/get-directus-graphql-client.ts

  • Use the generated graphql or ts schema to cover all available fields

  • Using tooo many fields is not an issue because we are only building occasionally, and having all fields available is really nice when developing the components

  • Fields not queried will still appear in the IDE because it doesn't parse the query but the generated .ts

  • Manually generating the query is technical debt (especially since we already automate the mapping of the directus schema to .ts)

  const result = await client.query<Query>(`
    query {
      pages {
        id
        slug
        title
        content
      }
      policies {
        id
        slug
        title
        content
      }
      posts {
        id
        slug
        title
        content
        user_created {
          first_name
          email
        }
        user_updated {
          first_name
          email
        }
        date_created
        date_updated
      }
    }
  `)
  • Cache the query result such that it doesn't need to be called for each slug... or is this already done?
  • Make sure any change in the type system causes a re-generate for both types and query - perhaps directus can call gitlab whenever that happens?
Edited by Flupsi