hongbo-miao/hongbomiao.com

View on GitHub
api-go/internal/graphql_server/schemas/user.go

Summary

Maintainability
A
0 mins
Test Coverage
package schemas

import (
    "github.com/graphql-go/graphql"
    "github.com/hongbo-miao/hongbomiao.com/api-go/internal/graphql_server/utils"
    "github.com/rs/zerolog/log"
)

var userGraphQLType = graphql.NewObject(graphql.ObjectConfig{
    Name: "User",
    Fields: graphql.Fields{
        "id": &graphql.Field{
            Type: graphql.ID,
        },
        "name": &graphql.Field{
            Type: graphql.String,
        },
    },
})

var userGraphQLField = graphql.Field{
    Type: userGraphQLType,
    Args: graphql.FieldConfigArgument{
        "id": &graphql.ArgumentConfig{
            Type: graphql.NewNonNull(graphql.ID),
        },
    },
    Resolve: func(p graphql.ResolveParams) (interface{}, error) {
        err := utils.CheckGraphQLContextMyID(p)
        if err != nil {
            log.Error().Err(err).Msg("CheckGraphQLContextMyID")
            return nil, err
        }

        id := p.Args["id"].(string)
        return utils.GetUser(id)
    },
}