added in graphql client

This commit is contained in:
2024-11-01 23:19:56 +05:30
parent 1fb2d7d154
commit 46c46a7e71
29 changed files with 2453 additions and 585 deletions

9
graph/auth.gql.ts Normal file
View File

@@ -0,0 +1,9 @@
import { gql } from '@urql/svelte';
export const QryMe = gql`
query Me {
me {
id
displayName
}
}
`;

View File

@@ -2,3 +2,17 @@ extend type Mutation {
login(username: String!, email: String!): Boolean!
logout: Boolean!
}
extend type Query {
"""
me, is current AuthUser info
"""
me: AuthUser
}
type AuthUser {
id: ID!
email: String!
displayName: String!
roleID: Int!
}

View File

@@ -7,6 +7,8 @@ package graph
import (
"context"
"fmt"
"gitserver.in/patialtech/rano/graph/model"
)
// Login is the resolver for the login field.
@@ -18,3 +20,8 @@ func (r *mutationResolver) Login(ctx context.Context, username string, email str
func (r *mutationResolver) Logout(ctx context.Context) (bool, error) {
panic(fmt.Errorf("not implemented: Logout - logout"))
}
// Me is the resolver for the me field.
func (r *queryResolver) Me(ctx context.Context) (*model.AuthUser, error) {
panic(fmt.Errorf("not implemented: Me - me"))
}

51
graph/d.ts Normal file
View File

@@ -0,0 +1,51 @@
export type Maybe<T> = T | null;
export type InputMaybe<T> = Maybe<T>;
export type Exact<T extends { [key: string]: unknown }> = { [K in keyof T]: T[K] };
export type MakeOptional<T, K extends keyof T> = Omit<T, K> & { [SubKey in K]?: Maybe<T[SubKey]> };
export type MakeMaybe<T, K extends keyof T> = Omit<T, K> & { [SubKey in K]: Maybe<T[SubKey]> };
export type MakeEmpty<T extends { [key: string]: unknown }, K extends keyof T> = { [_ in K]?: never };
export type Incremental<T> = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never };
/** All built-in and custom scalars, mapped to their actual values */
export type Scalars = {
ID: { input: string; output: string; }
String: { input: string; output: string; }
Boolean: { input: boolean; output: boolean; }
Int: { input: number; output: number; }
Float: { input: number; output: number; }
Any: { input: any; output: any; }
Map: { input: any; output: any; }
Time: { input: any; output: any; }
Void: { input: any; output: any; }
};
export type AuthUser = {
__typename?: 'AuthUser';
displayName: Scalars['String']['output'];
email: Scalars['String']['output'];
id: Scalars['ID']['output'];
roleID: Scalars['Int']['output'];
};
export type Mutation = {
__typename?: 'Mutation';
login: Scalars['Boolean']['output'];
logout: Scalars['Boolean']['output'];
};
export type MutationLoginArgs = {
email: Scalars['String']['input'];
username: Scalars['String']['input'];
};
export type Query = {
__typename?: 'Query';
heartBeat: Scalars['Boolean']['output'];
/** me, is current AuthUser info */
me?: Maybe<AuthUser>;
};
export type MeQueryVariables = Exact<{ [key: string]: never; }>;
export type MeQuery = { __typename?: 'Query', me?: { __typename?: 'AuthUser', id: string, displayName: string } | null };

View File

@@ -0,0 +1,283 @@
// Code generated by github.com/99designs/gqlgen, DO NOT EDIT.
package generated
import (
"context"
"errors"
"strconv"
"sync/atomic"
"github.com/99designs/gqlgen/graphql"
"github.com/vektah/gqlparser/v2/ast"
"gitserver.in/patialtech/rano/graph/model"
)
// region ************************** generated!.gotpl **************************
// endregion ************************** generated!.gotpl **************************
// region ***************************** args.gotpl *****************************
// endregion ***************************** args.gotpl *****************************
// region ************************** directives.gotpl **************************
// endregion ************************** directives.gotpl **************************
// region **************************** field.gotpl *****************************
func (ec *executionContext) _AuthUser_id(ctx context.Context, field graphql.CollectedField, obj *model.AuthUser) (ret graphql.Marshaler) {
fc, err := ec.fieldContext_AuthUser_id(ctx, field)
if err != nil {
return graphql.Null
}
ctx = graphql.WithFieldContext(ctx, fc)
defer func() {
if r := recover(); r != nil {
ec.Error(ctx, ec.Recover(ctx, r))
ret = graphql.Null
}
}()
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
ctx = rctx // use context from middleware stack in children
return obj.ID, nil
})
if err != nil {
ec.Error(ctx, err)
return graphql.Null
}
if resTmp == nil {
if !graphql.HasFieldError(ctx, fc) {
ec.Errorf(ctx, "must not be null")
}
return graphql.Null
}
res := resTmp.(string)
fc.Result = res
return ec.marshalNID2string(ctx, field.Selections, res)
}
func (ec *executionContext) fieldContext_AuthUser_id(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
fc = &graphql.FieldContext{
Object: "AuthUser",
Field: field,
IsMethod: false,
IsResolver: false,
Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) {
return nil, errors.New("field of type ID does not have child fields")
},
}
return fc, nil
}
func (ec *executionContext) _AuthUser_email(ctx context.Context, field graphql.CollectedField, obj *model.AuthUser) (ret graphql.Marshaler) {
fc, err := ec.fieldContext_AuthUser_email(ctx, field)
if err != nil {
return graphql.Null
}
ctx = graphql.WithFieldContext(ctx, fc)
defer func() {
if r := recover(); r != nil {
ec.Error(ctx, ec.Recover(ctx, r))
ret = graphql.Null
}
}()
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
ctx = rctx // use context from middleware stack in children
return obj.Email, nil
})
if err != nil {
ec.Error(ctx, err)
return graphql.Null
}
if resTmp == nil {
if !graphql.HasFieldError(ctx, fc) {
ec.Errorf(ctx, "must not be null")
}
return graphql.Null
}
res := resTmp.(string)
fc.Result = res
return ec.marshalNString2string(ctx, field.Selections, res)
}
func (ec *executionContext) fieldContext_AuthUser_email(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
fc = &graphql.FieldContext{
Object: "AuthUser",
Field: field,
IsMethod: false,
IsResolver: false,
Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) {
return nil, errors.New("field of type String does not have child fields")
},
}
return fc, nil
}
func (ec *executionContext) _AuthUser_displayName(ctx context.Context, field graphql.CollectedField, obj *model.AuthUser) (ret graphql.Marshaler) {
fc, err := ec.fieldContext_AuthUser_displayName(ctx, field)
if err != nil {
return graphql.Null
}
ctx = graphql.WithFieldContext(ctx, fc)
defer func() {
if r := recover(); r != nil {
ec.Error(ctx, ec.Recover(ctx, r))
ret = graphql.Null
}
}()
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
ctx = rctx // use context from middleware stack in children
return obj.DisplayName, nil
})
if err != nil {
ec.Error(ctx, err)
return graphql.Null
}
if resTmp == nil {
if !graphql.HasFieldError(ctx, fc) {
ec.Errorf(ctx, "must not be null")
}
return graphql.Null
}
res := resTmp.(string)
fc.Result = res
return ec.marshalNString2string(ctx, field.Selections, res)
}
func (ec *executionContext) fieldContext_AuthUser_displayName(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
fc = &graphql.FieldContext{
Object: "AuthUser",
Field: field,
IsMethod: false,
IsResolver: false,
Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) {
return nil, errors.New("field of type String does not have child fields")
},
}
return fc, nil
}
func (ec *executionContext) _AuthUser_roleID(ctx context.Context, field graphql.CollectedField, obj *model.AuthUser) (ret graphql.Marshaler) {
fc, err := ec.fieldContext_AuthUser_roleID(ctx, field)
if err != nil {
return graphql.Null
}
ctx = graphql.WithFieldContext(ctx, fc)
defer func() {
if r := recover(); r != nil {
ec.Error(ctx, ec.Recover(ctx, r))
ret = graphql.Null
}
}()
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
ctx = rctx // use context from middleware stack in children
return obj.RoleID, nil
})
if err != nil {
ec.Error(ctx, err)
return graphql.Null
}
if resTmp == nil {
if !graphql.HasFieldError(ctx, fc) {
ec.Errorf(ctx, "must not be null")
}
return graphql.Null
}
res := resTmp.(int)
fc.Result = res
return ec.marshalNInt2int(ctx, field.Selections, res)
}
func (ec *executionContext) fieldContext_AuthUser_roleID(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
fc = &graphql.FieldContext{
Object: "AuthUser",
Field: field,
IsMethod: false,
IsResolver: false,
Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) {
return nil, errors.New("field of type Int does not have child fields")
},
}
return fc, nil
}
// endregion **************************** field.gotpl *****************************
// region **************************** input.gotpl *****************************
// endregion **************************** input.gotpl *****************************
// region ************************** interface.gotpl ***************************
// endregion ************************** interface.gotpl ***************************
// region **************************** object.gotpl ****************************
var authUserImplementors = []string{"AuthUser"}
func (ec *executionContext) _AuthUser(ctx context.Context, sel ast.SelectionSet, obj *model.AuthUser) graphql.Marshaler {
fields := graphql.CollectFields(ec.OperationContext, sel, authUserImplementors)
out := graphql.NewFieldSet(fields)
deferred := make(map[string]*graphql.FieldSet)
for i, field := range fields {
switch field.Name {
case "__typename":
out.Values[i] = graphql.MarshalString("AuthUser")
case "id":
out.Values[i] = ec._AuthUser_id(ctx, field, obj)
if out.Values[i] == graphql.Null {
out.Invalids++
}
case "email":
out.Values[i] = ec._AuthUser_email(ctx, field, obj)
if out.Values[i] == graphql.Null {
out.Invalids++
}
case "displayName":
out.Values[i] = ec._AuthUser_displayName(ctx, field, obj)
if out.Values[i] == graphql.Null {
out.Invalids++
}
case "roleID":
out.Values[i] = ec._AuthUser_roleID(ctx, field, obj)
if out.Values[i] == graphql.Null {
out.Invalids++
}
default:
panic("unknown field " + strconv.Quote(field.Name))
}
}
out.Dispatch(ctx)
if out.Invalids > 0 {
return graphql.Null
}
atomic.AddInt32(&ec.deferred, int32(len(deferred)))
for label, dfs := range deferred {
ec.processDeferredGroup(graphql.DeferredGroup{
Label: label,
Path: graphql.GetPath(ctx),
FieldSet: dfs,
Context: ctx,
})
}
return out
}
// endregion **************************** object.gotpl ****************************
// region ***************************** type.gotpl *****************************
func (ec *executionContext) marshalOAuthUser2ᚖgitserverᚗinᚋpatialtechᚋranoᚋgraphᚋmodelᚐAuthUser(ctx context.Context, sel ast.SelectionSet, v *model.AuthUser) graphql.Marshaler {
if v == nil {
return graphql.Null
}
return ec._AuthUser(ctx, sel, v)
}
// endregion ***************************** type.gotpl *****************************

View File

@@ -12,6 +12,7 @@ import (
"github.com/99designs/gqlgen/graphql"
"github.com/99designs/gqlgen/graphql/introspection"
"github.com/vektah/gqlparser/v2/ast"
"gitserver.in/patialtech/rano/graph/model"
)
// region ************************** generated!.gotpl **************************
@@ -22,6 +23,7 @@ type MutationResolver interface {
}
type QueryResolver interface {
HeartBeat(ctx context.Context) (bool, error)
Me(ctx context.Context) (*model.AuthUser, error)
}
// endregion ************************** generated!.gotpl **************************
@@ -243,6 +245,57 @@ func (ec *executionContext) fieldContext_Query_heartBeat(_ context.Context, fiel
return fc, nil
}
func (ec *executionContext) _Query_me(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) {
fc, err := ec.fieldContext_Query_me(ctx, field)
if err != nil {
return graphql.Null
}
ctx = graphql.WithFieldContext(ctx, fc)
defer func() {
if r := recover(); r != nil {
ec.Error(ctx, ec.Recover(ctx, r))
ret = graphql.Null
}
}()
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
ctx = rctx // use context from middleware stack in children
return ec.resolvers.Query().Me(rctx)
})
if err != nil {
ec.Error(ctx, err)
return graphql.Null
}
if resTmp == nil {
return graphql.Null
}
res := resTmp.(*model.AuthUser)
fc.Result = res
return ec.marshalOAuthUser2ᚖgitserverᚗinᚋpatialtechᚋranoᚋgraphᚋmodelᚐAuthUser(ctx, field.Selections, res)
}
func (ec *executionContext) fieldContext_Query_me(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
fc = &graphql.FieldContext{
Object: "Query",
Field: field,
IsMethod: true,
IsResolver: true,
Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) {
switch field.Name {
case "id":
return ec.fieldContext_AuthUser_id(ctx, field)
case "email":
return ec.fieldContext_AuthUser_email(ctx, field)
case "displayName":
return ec.fieldContext_AuthUser_displayName(ctx, field)
case "roleID":
return ec.fieldContext_AuthUser_roleID(ctx, field)
}
return nil, fmt.Errorf("no field named %q was found under type AuthUser", field.Name)
},
}
return fc, nil
}
func (ec *executionContext) _Query___type(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) {
fc, err := ec.fieldContext_Query___type(ctx, field)
if err != nil {
@@ -480,6 +533,25 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr
func(ctx context.Context) graphql.Marshaler { return innerFunc(ctx, out) })
}
out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return rrm(innerCtx) })
case "me":
field := field
innerFunc := func(ctx context.Context, _ *graphql.FieldSet) (res graphql.Marshaler) {
defer func() {
if r := recover(); r != nil {
ec.Error(ctx, ec.Recover(ctx, r))
}
}()
res = ec._Query_me(ctx, field)
return res
}
rrm := func(ctx context.Context) graphql.Marshaler {
return ec.OperationContext.RootResolverMiddleware(ctx,
func(ctx context.Context) graphql.Marshaler { return innerFunc(ctx, out) })
}
out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return rrm(innerCtx) })
case "__type":
out.Values[i] = ec.OperationContext.RootResolverMiddleware(innerCtx, func(ctx context.Context) (res graphql.Marshaler) {

View File

@@ -2256,6 +2256,36 @@ func (ec *executionContext) marshalNBoolean2bool(ctx context.Context, sel ast.Se
return res
}
func (ec *executionContext) unmarshalNID2string(ctx context.Context, v interface{}) (string, error) {
res, err := graphql.UnmarshalID(v)
return res, graphql.ErrorOnPath(ctx, err)
}
func (ec *executionContext) marshalNID2string(ctx context.Context, sel ast.SelectionSet, v string) graphql.Marshaler {
res := graphql.MarshalID(v)
if res == graphql.Null {
if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) {
ec.Errorf(ctx, "the requested element is null which the schema does not allow")
}
}
return res
}
func (ec *executionContext) unmarshalNInt2int(ctx context.Context, v interface{}) (int, error) {
res, err := graphql.UnmarshalInt(v)
return res, graphql.ErrorOnPath(ctx, err)
}
func (ec *executionContext) marshalNInt2int(ctx context.Context, sel ast.SelectionSet, v int) graphql.Marshaler {
res := graphql.MarshalInt(v)
if res == graphql.Null {
if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) {
ec.Errorf(ctx, "the requested element is null which the schema does not allow")
}
}
return res
}
func (ec *executionContext) unmarshalNString2string(ctx context.Context, v interface{}) (string, error) {
res, err := graphql.UnmarshalString(v)
return res, graphql.ErrorOnPath(ctx, err)

View File

@@ -40,6 +40,13 @@ type DirectiveRoot struct {
}
type ComplexityRoot struct {
AuthUser struct {
DisplayName func(childComplexity int) int
Email func(childComplexity int) int
ID func(childComplexity int) int
RoleID func(childComplexity int) int
}
Mutation struct {
Login func(childComplexity int, username string, email string) int
Logout func(childComplexity int) int
@@ -47,6 +54,7 @@ type ComplexityRoot struct {
Query struct {
HeartBeat func(childComplexity int) int
Me func(childComplexity int) int
}
}
@@ -69,6 +77,34 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in
_ = ec
switch typeName + "." + field {
case "AuthUser.displayName":
if e.complexity.AuthUser.DisplayName == nil {
break
}
return e.complexity.AuthUser.DisplayName(childComplexity), true
case "AuthUser.email":
if e.complexity.AuthUser.Email == nil {
break
}
return e.complexity.AuthUser.Email(childComplexity), true
case "AuthUser.id":
if e.complexity.AuthUser.ID == nil {
break
}
return e.complexity.AuthUser.ID(childComplexity), true
case "AuthUser.roleID":
if e.complexity.AuthUser.RoleID == nil {
break
}
return e.complexity.AuthUser.RoleID(childComplexity), true
case "Mutation.login":
if e.complexity.Mutation.Login == nil {
break
@@ -95,6 +131,13 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in
return e.complexity.Query.HeartBeat(childComplexity), true
case "Query.me":
if e.complexity.Query.Me == nil {
break
}
return e.complexity.Query.Me(childComplexity), true
}
return 0, false
}
@@ -203,6 +246,20 @@ var sources = []*ast.Source{
login(username: String!, email: String!): Boolean!
logout: Boolean!
}
extend type Query {
"""
me, is current AuthUser info
"""
me: AuthUser
}
type AuthUser {
id: ID!
email: String!
displayName: String!
roleID: Int!
}
`, BuiltIn: false},
{Name: "../index.graphql", Input: `# GraphQL schema example
#

View File

@@ -2,6 +2,13 @@
package model
type AuthUser struct {
ID string `json:"id"`
Email string `json:"email"`
DisplayName string `json:"displayName"`
RoleID int `json:"roleID"`
}
type Mutation struct {
}