How do I change the case with mesh transforms in all the extended types?

27 Views Asked by At

I am struggling to use naming conventions in mesh transform

transforms:
  - namingConvention:
      fieldNames: snakeCase

to change all keys to be snake_case. Though they do change the cases in the top level, but my additional_resolver look something like this:

Claim: {
    policy_holder: {
      selectionSet: `{ policyholder_id }`,
      resolve: async (root, args, context, info) => {
        console.log('Claim.policyholder resolver:');
        console.log('root:', root);
        console.log('args:', args);
        console.log('context keys:', Object.keys(context));
        console.log('info.fieldName:', info.fieldName);

        try {
          const result = await context.PoliciesDatabase.Query.policyById({
            args: {
              id: root.policyholder_id,
            },
            context,
            info,
          });
          console.log('Query result:', result);
          return result;
        } catch (error) {
          console.error('Error in policyholder resolver:', error);
          throw error;
        }
      },
    }
  },

My response look like this:

{
    "errors": [
        {
            "message": "Cannot return null for non-nullable field Policy.firstName.",
            "path": [
                "all_policies_list",
                0,
                "policy_holder",
                "first_name"
            ]
        },
    ],
    "data": {
        "all_policies_list": [
            {
                "id": "018d8178-b7d5-795b-96c5-4e9c77f93895",

                "location_city": "SF",
                "location_state": "CA",
                "location_country": "USA",
                "location_zip": "94114",
                "status": "PENDING",
                "policyholder_id": "018d3e1b-2374-7556-86e9-d4874446ca28",
                "policy_holder": null
            },
            
        ]
    }
}

But ideally, I want something like:

    "data": {
        "all_policies_list": [
            {
                "id": "018d8178-b7d5-795b-96c5-4e9c77f93895",

                "location_city": "SF",
                "location_state": "CA",
                "location_country": "USA",
                "location_zip": "94114",
                "status": "PENDING",
                "policyholder_id": "018d3e1b-2374-7556-86e9-d4874446ca28",
                "policy_holder": {
                    "home_address": "...",
                    "first_name": "..."
                }
            },
            
        ]
    }

I have tried using home_address and homeAddress (Was working before the transforms). I am running out of ideas. Thank you so much!

0

There are 0 best solutions below