10000 Resolver of a nested Type is not triggered. · Issue #337 · graphql-compose/graphql-compose · GitHub
[go: up one dir, main page]

Skip to content
Resolver of a nested Type is not triggered. #337
Open
@innovaweb-dev

Description

@innovaweb-dev

AddressTC is a reusable Type, when UserTC or another Type is created or updated, I whant to trigger validation automatically of AddressTC. If you know a better way to do that, I'll take it. With the code above, when I create or update User, resolever of AddressTC is not triggered.

// In this example I'll use UserTC but this can another type which also use AdressTC.

const UserTC = schemaComposer.createObjectTC({
    name: 'User',
    fields: {
        id: 'String',
        name: 'String',
        slug: 'String',
        actived: 'Boolean',
        registered: 'Boolean',
        address: AddressTC,
    }
});

const UserITC = UserTC.getInputTypeComposer()

UserTC.addResolver({
    kind: 'mutation',
    name: 'create',
    args: {
        data: UserITC
    },
    type: UserTC,
    resolve: async ({args: {data}, context}) => {
        // What I'll want it does : to trigger validation and geocode of AddressTC
        // What it does currently, GraphQL ignore AdressTC data and it just save data without validate
    },
})
// reusable Address Type

const AddressTC = schemaComposer.createObjectTC({
    name: 'Address',
    description: 'Type of address',
    fields: {
        street: 'String',
        number: 'String',
        postcode: 'String',
        city: 'String',
        comment: 'String',
        country: 'String',
        quality: QualityETC
    }
});

const AddressITC = AddressTC.getInputTypeComposer()

AddressTC.addResolver({
    kind: 'mutation',
    name: 'validation',
    args: {
        data: AddressITC
    },
    type: AddressTC,
    resolve: async ({args: {data}, context}) => {
        // When address is puted or updated :
        // => Make validation
        // => Geocode {Lat,Lng} with map provider 
        // Save in DB           
    },
})

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0