Adding new fields to read the value GraphQL & Components Service

Hi Codebots Team,

I was new to graphQL thing and wondering what is the correct way to read the value of relations to other entities on the Angular Components Service on GraphQL parts.

at the moment I do this read the value on the relations from other Entities, but sometimes if we rebuild code bots and add another entity the added entity was not written here due we put this on.

Thank you

Hi @Virgananta_Nugraha,

Based on what you’ve told us it appears that your issue is due to the protected region being turned on. Turning on the protected region will preserve any custom code changes that you have made, but it will also prevent new bot written code from being added into that protected region, which may happen regularly if you are making model changes. This is unfortunately a fundamental part of how the bots work and is not possible for us to change.

To update the code inside a protected region, you will either need to manually edit it, or follow these steps to merge additional bot written changes into a protected region:

  1. Create a new branch with your custom changes
  2. Turn off the protected region in develop and commit the result. This will allow the bot to write the code into the protected region
  3. Build the project on the platform
  4. Copy/Merge the changes in your created branch and reactivate the protected region

Thanks @Toby

Just to clarify my question,
By default Registration Properties Fragment only contains the data for a single entity, in this case, its only contain properties from the registration entity. What I want is to add related entities fields to this fragment?
so I can retrieve the registration and its related entities in one call.

Is there a better place in the code where I should put my custom code? without affecting the code generated by Bots. Because I saw in service there is Get, create, create all and etc

Hi @Virgananta_Nugraha, thanks for the clarification.

The best way to handle that would not be by modifying the registration properties. Instead you should add expands objects to the query params that are being passed into this method.

An expand option contains the name of the relation, and a list of all of the attributes of the related entity which you want to fetch. The names of the attributes will be the same as the name of the props in the entities getProps() method.

An example of an Expand object for the bed facility relation you pasted before would look like this:

    name: 'bedFacility',
    fields: ['id', 'created', 'modified', 'bedNumber', 'bedName', 'roomFacility { roomName location }']

This can be added to the query parameters for your get query, and it will fetch objects as part of the query, so you don’t need to modify the bot written graphql query.


Hi @Toby Thanks for the answer now i follow this method.

1 Like