Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make generated graphql entity non optional #20419

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

msadegh76
Copy link

@msadegh76 msadegh76 commented Jun 1, 2024

fixes #11815

What does it do?

It makes the "EntityResponseCollection" and "id" and "attributes" key of generated graphql "Entity" non optional.

Why is it needed?

Working with typescript in Strapi is tedious because the aforementioned attributes/types are marked as optional.

The code requires a number of type assertions or optional chaining constructs to eliminate the undefined/null types leading to obscure and hard to read code.

How to test it?

In Strapi create a simple content type with two non-optional attributes, namely 'title' and 'description'.

The currently generated Schema portion looks as follows:

// Current generated schema portion

type Post {
  title: String!
  description: String!
  createdAt: DateTime
  updatedAt: DateTime
  publishedAt: DateTime
}

type PostEntity {
  id: ID
  attributes: Post
}

type PostEntityResponse {
  data: PostEntity
}

type PostEntityResponseCollection {
  data: [PostEntity!]!
  meta: ResponseCollectionMeta!
}

After applying this patch the schema will instead contain the following types:

// Desired generated schema portion

type Post {
  title: String!
  description: String!
  createdAt: DateTime
  updatedAt: DateTime
  publishedAt: DateTime
}

type PostEntity {
  id: ID!
  attributes: Post!
}

type PostEntityResponse {
  data: PostEntity!
}

type PostEntityResponseCollection {
  data: [PostEntity!]!
  meta: ResponseCollectionMeta!
}

Related issue(s)/PR(s)

#9411

Copy link

vercel bot commented Jun 1, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
contributor-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 1, 2024 2:41pm

@strapi-cla
Copy link

strapi-cla commented Jun 1, 2024

CLA assistant check
All committers have signed the CLA.

@msadegh76 msadegh76 changed the title Make generated graphql entity non optional [WIP] Make generated graphql entity non optional Jun 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[v4] set GraphQL-Entity props required
2 participants