Skip to content

[BUG] Fails at runtime when a resolver is missing in a mapper #365

@olalonde

Description

@olalonde

I noticed that the generated types for mappers have all fields marked as optional so if you delete one of them, typescript won't notice but it will fail at runtime. Is this intended?

For example:

type Vehicle {
  id: ID!
  telemetryLogs: [TelemetryLog!]!
}

I have this mapper:

Vehicle.ts

import type { VehicleResolvers } from "../../types.generated.ts";
export const Vehicle: VehicleResolvers = {
  telemetryLogs: async (_parent, _arg, _ctx) => {
    /* Vehicle.telemetryLogs resolver is required because Vehicle.telemetryLogs exists but VehicleMapper.telemetryLogs does not */
  },
};

I am able to completely remove the telemetryLogs property:

import type { VehicleResolvers } from "../../types.generated.ts";
export const Vehicle: VehicleResolvers = {
  // telemetryLogs: async (_parent, _arg, _ctx) => {
    /* Vehicle.telemetryLogs resolver is required because Vehicle.telemetryLogs exists but VehicleMapper.telemetryLogs does not */
  // },
};

... it will still compile fine with typescript. However, since latestTelemetry is non nullable in my GraphQL schema, it will fail with a runtime an error when I query it.

In the generated.types.ts file

export type VehicleResolvers<ContextType = GraphQLContext, ParentType extends ResolversParentTypes['Vehicle'] = ResolversParentTypes['Vehicle']> = {
  id?: Resolver<ResolversTypes['ID'], ParentType, ContextType>;
  telemetryLogs?: Resolver<Array<ResolversTypes['TelemetryLog']>, ParentType, ContextType>;
  __isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>;
};

The problem is that telemetryLogs?: should really be telemetryLogs:. Isn't it?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions