overblog / GraphQLBundle

This bundle provides tools to build a complete GraphQL API server in your Symfony App.
MIT License
780 stars 223 forks source link

Help: Unclear how to use validation "link" with mutation/input objects #1180

Closed joesaunderson closed 3 months ago

joesaunderson commented 3 months ago
Q A
Bug report? no
Feature request? no
BC Break report? no
RFC? no
Version/Branch 1

I am trying to use the validation linking as documented here but I am struggling, and getting exceptions.

Mutation:

EntityMutation:
    type: object
    heirs:
        - Mutation
    config:
        fields:
            edit_Entity:
                type: "Entity!"
                args:
                    entityId:
                        type: "ID!"
                    set:
                        type: "EntityEditInput!"
                        validation: cascade
                resolve: '@=query("App/Resolver::editEntity", args)'

Input Object

EntityEditInput:
    type: input-object
    config:
        fields:
            displayName:
                type: "String"
                validation:
                    link: 'App\Entity::$Name'

Exception

Property Overblog\\GraphQLBundle\\Validator\\ValidationNode::$Name does not exist

I noted this was mentioned here but can you help me understand what the "correct" way of linking class constraints here would be (using an input object).

joesaunderson commented 3 months ago

@Vincz @mcg-web, sorry for the direct tag. Can you tell me if I'm doing something obviously wrong here?

Ultimately, we wan't to use existing rules to validate fields within an input object, which is then used in a mutation.

joesaunderson commented 3 months ago

Further debugging shows this is a naming / case sensitivity thing... the property on our entity was named $Name where the input field was called displayName

It wasn't obvious to me they needed to match identically - is it worth calling that out in the docs? Or even better, breaking the dependency between the input field name and the entity field name being identical?