Skip to content

Commit

Permalink
implements the resolver using ent client
Browse files Browse the repository at this point in the history
  • Loading branch information
Arthur1 committed Sep 10, 2023
1 parent 82bf7c1 commit 6136071
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
9 changes: 4 additions & 5 deletions graph/ent.resolvers.go
Expand Up @@ -5,27 +5,26 @@ package graph

import (
"context"
"fmt"

"entgo.io/contrib/entgql"
"github.com/Arthur1/economical-graphql-server-demo/ent"
"github.com/Arthur1/economical-graphql-server-demo/graph/generated"
)

func (r *queryResolver) Node(ctx context.Context, id int) (ent.Noder, error) {
panic(fmt.Errorf("not implemented"))
return r.Client.Noder(ctx, id, ent.WithFixedNodeType(getTypeFromID(id)))
}

func (r *queryResolver) Nodes(ctx context.Context, ids []int) ([]ent.Noder, error) {
panic(fmt.Errorf("not implemented"))
return r.Client.Noders(ctx, ids)
}

func (r *queryResolver) Artists(ctx context.Context, after *entgql.Cursor[int], first *int, before *entgql.Cursor[int], last *int, where *ent.ArtistWhereInput) (*ent.ArtistConnection, error) {
panic(fmt.Errorf("not implemented"))
return r.Client.Artist.Query().Paginate(ctx, after, first, before, last, ent.WithArtistFilter(where.Filter))
}

func (r *queryResolver) Songs(ctx context.Context, after *entgql.Cursor[int], first *int, before *entgql.Cursor[int], last *int, where *ent.SongWhereInput) (*ent.SongConnection, error) {
panic(fmt.Errorf("not implemented"))
return r.Client.Song.Query().Paginate(ctx, after, first, before, last, ent.WithSongFilter(where.Filter))
}

// Query returns generated.QueryResolver implementation.
Expand Down
18 changes: 17 additions & 1 deletion graph/resolver.go
@@ -1,7 +1,23 @@
package graph

import (
"github.com/Arthur1/economical-graphql-server-demo/ent"
"github.com/Arthur1/economical-graphql-server-demo/ent/artist"
"github.com/Arthur1/economical-graphql-server-demo/ent/song"
)

// This file will not be regenerated automatically.
//
// It serves as dependency injection for your app, add any dependencies you require here.

type Resolver struct{}
type Resolver struct {
Client *ent.Client
}

func getTypeFromID(id int) string {
if id > 1000 {
return artist.Table
} else {
return song.Table
}
}

0 comments on commit 6136071

Please sign in to comment.