Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
james-em opened this issue Feb 7, 2024 · 1 comment
Open
Assignees

Comments

@james-em
Copy link

james-em commented Feb 7, 2024

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"
            ],
            /* ... */ 
    }
}
@jamesedmonston jamesedmonston self-assigned this Feb 10, 2024
@jamesedmonston
Copy link
Owner

Does this work when querying after the authenticate mutation? The plugin is just returning Craft's built-in User type here, so it should be working correctly: https://github.com/jamesedmonston/graphql-authentication/blob/develop/src/gql/Auth.php#L32

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants