Skip to content

Question: Authenticate mutation return custom column from custom table? #144

@ghost

Description

Hi,

I have the following mutation which works just fine

      authenticate(email: $email, password: $password) {
        jwt
        jwtExpiresAt
        refreshToken
        refreshTokenExpiresAt
        user {
          ... on User {
            uid
            email
            firstName
            siteId
          }
        }
      }
    }

However, I would like to pull as well 2 custom columns that are in custom tables:

      authenticate(email: $email, password: $password) {
        jwt
        jwtExpiresAt
        refreshToken
        refreshTokenExpiresAt
        user {
          ... on User {
            uid
            email
            firstName
            siteId
            details {
              ... on UserDetails {
                inscriptionLastStep
                inscriptionVersion
              }
            }
          }
        }
      }

but I get this error

{
    "errors": [
        {
            "message": "Cannot query field \"details\" on type \"User\". Did you mean \"email\"?",
            "extensions": {
                "category": "graphql"
            },
            "locations": [
                {
                    "line": 13,
                    "column": 9
                }
            ]
        }
    ]
}

I don't see any way where I can extend the "User" type but in my app I do have a CustomUser for arguments, interfaces, mutations, queries and resolvers.

Exemple

use craft\gql\interfaces\elements\User;

class CustomUser extends User {


    public static function getName(): string { /* ... */ }

    public static function getType($fields = null): Type { /* ... */ }

  
    public static function getFieldDefinitions(): array { /* ... */ }

    public static function getCustomFieldDefinitions(): array  { 
           /* ... */ 
           'details' => [
                'name' => 'details',
                'type' => UserDetails::getType(),
                'description' => "Details of an user"
            ],
            /* ... */ 
    }
}

Metadata

Metadata

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions