Code Monkey home page Code Monkey logo

Comments (4)

Ekkeir avatar Ekkeir commented on July 19, 2024 1

I'm not nearly @sungam3r, but as of now you're returning usuariodb value, which seems to be an instance of System.String,WebAppEF1.Models.Usuario while your intention is seemingly to return the token and IdUser

Assuming that LoginType is defined something like the following

class LoginType : ObjectGraphType<Login>
{
    public LoginType()
    {
        Field(x => x.Token);
        Field(x => x.IdUser);
    } 
}

and Login is defined something like this

class Login
{
    public string Token;
    public string IdUser;
}

then you'd have to combine it all in your resolver like this presumably

public class LoginAuth : ObjectGraphType
    {
        ...

        public LoginAuth(DataContext context, IConfiguration configuration)
        {
             ...             
             resolve: context =>
             {
                                 
                 ....
   
                 var usuariodb = _context.Usuarios.SingleOrDefault(x => x.Email == login.Email && x.Contrasena == login.Contrasena);
    
                 ...
             
                 var tokenUser = CreateToken(usuariodb);
 
                 // the only changed part here
                 return new Login { Token = tokenUser, IdUser = usuariodb.IdUser };
             });

        }

It is not precise, but should be somewhere close.

P.S. and your mutation would look approximately like this, I think
mutation($login: LoginInput!) { login(login: $login) { IdUser login } }

from authorization.

sungam3r avatar sungam3r commented on July 19, 2024

Please specify what question you have.

from authorization.

AAIING avatar AAIING commented on July 19, 2024

Please specify what question you have.

Hi Ivan, my question is how to trying a mutation login (username and password) and in the response query only show the token and id_user. you understand?

error:
image

Error: "(eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJuYW1laWQiOiIxIiwidW5pcXVlX25hbWUiOiJwZXBpdG9AcGVyZXouY2wiLCJuYmYiOjE2MDM4MzA1MTYsImV4cCI6MTYwMzkxNjkxNiwiaWF0IjoxNjAzODMwNTE2fQ.mQ9IV8iL-IBG8SIaWD69uFBnpgA0bK35tE-ppP4f6q6eDtEUJKpL8ICXb7XrYYxOBD2WRBrP9yjl9e_uRW00xg, WebAppEF1.Models.Usuario)" value of type "System.ValueTuple`2[System.String,WebAppEF1.Models.Usuario]" is not allowed for "LoginType". Either change IsTypeOf method of "LoginType" to accept this value or return another value from your resolver.

i buy a coffe for you!!

from authorization.

sungam3r avatar sungam3r commented on July 19, 2024

You return object of type System.ValueTuple2[System.String,WebAppEF1.Models.Usuario] from resolver for field "login" but that field has type LoginType which is not compatible with returned object. The error message is quite verbose. This check happens inside protected virtual void ValidateNodeResult(ExecutionContext context, ExecutionNode node):

if (objectType?.IsTypeOf != null && !objectType.IsTypeOf(result))
{
     throw new InvalidOperationException($"\"{result}\" value of type \"{result.GetType()}\" is not allowed for \"{objectType.Name}\". Either change IsTypeOf method of \"{objectType.Name}\" to accept this value or return another value from your resolver.");
}

Please provide definition of LoginType to investigate further.

from authorization.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.