Commit aa7af620 authored by k1350's avatar k1350
Browse files

[update] 色々修正

- マスタパラメータ取得クエリを1リソース1APIに修正
- bloglinkリポジトリをblogリポジトリに統合
- blogリポジトリにテスト作成
- blogとarticleで日時はリポジトリ内で変換するよう修正
- react-queryバージョンアップ
- フロント側で画面から離れるたびにAPIが呼ばれてしまう点を修正
parent 2941c38c
......@@ -36,7 +36,6 @@ type Config struct {
}
type ResolverRoot interface {
Article() ArticleResolver
Blog() BlogResolver
Mutation() MutationResolver
Query() QueryResolver
......@@ -85,6 +84,11 @@ type ComplexityRoot struct {
URL func(childComplexity int) int
}
MasterParameter struct {
MaxBlogLinks func(childComplexity int) int
MaxBlogs func(childComplexity int) int
}
Mutation struct {
CreateArticle func(childComplexity int, input model.CreateArticleInput) int
CreateBlog func(childComplexity int, input model.CreateBlogInput) int
......@@ -107,19 +111,12 @@ type ComplexityRoot struct {
BlogByID func(childComplexity int, id string) int
BlogPublishOption func(childComplexity int, blogKey string) int
Blogs func(childComplexity int) int
MaxBlogLinks func(childComplexity int) int
MaxBlogs func(childComplexity int) int
MasterParameter func(childComplexity int) int
}
}
type ArticleResolver interface {
CreatedAt(ctx context.Context, obj *model.Article) (string, error)
UpdatedAt(ctx context.Context, obj *model.Article) (string, error)
}
type BlogResolver interface {
Links(ctx context.Context, obj *model.Blog) ([]*model.BlogLink, error)
CreatedAt(ctx context.Context, obj *model.Blog) (string, error)
UpdatedAt(ctx context.Context, obj *model.Blog) (string, error)
}
type MutationResolver interface {
CreateBlog(ctx context.Context, input model.CreateBlogInput) (*model.Blog, error)
......@@ -135,8 +132,7 @@ type QueryResolver interface {
BlogByBlogKey(ctx context.Context, input model.BlogByBlogKeyInput) (*model.Blog, error)
BlogPublishOption(ctx context.Context, blogKey string) (*model.PublishOption, error)
Articles(ctx context.Context, input model.BlogByBlogKeyInput, paginationInput model.ArticlePaginationInput) (*model.ArticleConnection, error)
MaxBlogs(ctx context.Context) (int, error)
MaxBlogLinks(ctx context.Context) (int, error)
MasterParameter(ctx context.Context) (*model.MasterParameter, error)
}
type executableSchema struct {
......@@ -294,6 +290,20 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in
return e.complexity.BlogLink.URL(childComplexity), true
case "MasterParameter.maxBlogLinks":
if e.complexity.MasterParameter.MaxBlogLinks == nil {
break
}
return e.complexity.MasterParameter.MaxBlogLinks(childComplexity), true
case "MasterParameter.maxBlogs":
if e.complexity.MasterParameter.MaxBlogs == nil {
break
}
return e.complexity.MasterParameter.MaxBlogs(childComplexity), true
case "Mutation.createArticle":
if e.complexity.Mutation.CreateArticle == nil {
break
......@@ -449,19 +459,12 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in
return e.complexity.Query.Blogs(childComplexity), true
case "Query.maxBlogLinks":
if e.complexity.Query.MaxBlogLinks == nil {
break
}
return e.complexity.Query.MaxBlogLinks(childComplexity), true
case "Query.maxBlogs":
if e.complexity.Query.MaxBlogs == nil {
case "Query.masterParameter":
if e.complexity.Query.MasterParameter == nil {
break
}
return e.complexity.Query.MaxBlogs(childComplexity), true
return e.complexity.Query.MasterParameter(childComplexity), true
}
return 0, false
......@@ -545,8 +548,7 @@ var sources = []*ast.Source{
blogByBlogKey(input: BlogByBlogKeyInput!): Blog
blogPublishOption(blogKey: String!): PublishOption
articles(input: BlogByBlogKeyInput!, paginationInput: ArticlePaginationInput!): ArticleConnection
maxBlogs: Int!
maxBlogLinks: Int!
masterParameter: MasterParameter
}
type Mutation {
......@@ -579,6 +581,11 @@ interface Connection {
edges: [Edge]
}
type MasterParameter {
maxBlogs: Int!
maxBlogLinks: Int!
}
type Blog {
id: ID!
blogKey: String!
......@@ -1150,7 +1157,7 @@ func (ec *executionContext) _Article_createdAt(ctx context.Context, field graphq
}()
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
ctx = rctx // use context from middleware stack in children
return ec.resolvers.Article().CreatedAt(rctx, obj)
return obj.CreatedAt, nil
})
if err != nil {
ec.Error(ctx, err)
......@@ -1171,8 +1178,8 @@ func (ec *executionContext) fieldContext_Article_createdAt(ctx context.Context,
fc = &graphql.FieldContext{
Object: "Article",
Field: field,
IsMethod: true,
IsResolver: true,
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")
},
......@@ -1194,7 +1201,7 @@ func (ec *executionContext) _Article_updatedAt(ctx context.Context, field graphq
}()
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
ctx = rctx // use context from middleware stack in children
return ec.resolvers.Article().UpdatedAt(rctx, obj)
return obj.UpdatedAt, nil
})
if err != nil {
ec.Error(ctx, err)
......@@ -1215,8 +1222,8 @@ func (ec *executionContext) fieldContext_Article_updatedAt(ctx context.Context,
fc = &graphql.FieldContext{
Object: "Article",
Field: field,
IsMethod: true,
IsResolver: true,
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")
},
......@@ -1750,7 +1757,7 @@ func (ec *executionContext) _Blog_createdAt(ctx context.Context, field graphql.C
}()
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
ctx = rctx // use context from middleware stack in children
return ec.resolvers.Blog().CreatedAt(rctx, obj)
return obj.CreatedAt, nil
})
if err != nil {
ec.Error(ctx, err)
......@@ -1771,8 +1778,8 @@ func (ec *executionContext) fieldContext_Blog_createdAt(ctx context.Context, fie
fc = &graphql.FieldContext{
Object: "Blog",
Field: field,
IsMethod: true,
IsResolver: true,
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")
},
......@@ -1794,7 +1801,7 @@ func (ec *executionContext) _Blog_updatedAt(ctx context.Context, field graphql.C
}()
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
ctx = rctx // use context from middleware stack in children
return ec.resolvers.Blog().UpdatedAt(rctx, obj)
return obj.UpdatedAt, nil
})
if err != nil {
ec.Error(ctx, err)
......@@ -1815,8 +1822,8 @@ func (ec *executionContext) fieldContext_Blog_updatedAt(ctx context.Context, fie
fc = &graphql.FieldContext{
Object: "Blog",
Field: field,
IsMethod: true,
IsResolver: true,
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")
},
......@@ -1956,6 +1963,94 @@ func (ec *executionContext) fieldContext_BlogLink_url(ctx context.Context, field
return fc, nil
}
func (ec *executionContext) _MasterParameter_maxBlogs(ctx context.Context, field graphql.CollectedField, obj *model.MasterParameter) (ret graphql.Marshaler) {
fc, err := ec.fieldContext_MasterParameter_maxBlogs(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.MaxBlogs, 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_MasterParameter_maxBlogs(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
fc = &graphql.FieldContext{
Object: "MasterParameter",
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
}
func (ec *executionContext) _MasterParameter_maxBlogLinks(ctx context.Context, field graphql.CollectedField, obj *model.MasterParameter) (ret graphql.Marshaler) {
fc, err := ec.fieldContext_MasterParameter_maxBlogLinks(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.MaxBlogLinks, 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_MasterParameter_maxBlogLinks(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
fc = &graphql.FieldContext{
Object: "MasterParameter",
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
}
func (ec *executionContext) _Mutation_createBlog(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) {
fc, err := ec.fieldContext_Mutation_createBlog(ctx, field)
if err != nil {
......@@ -2828,8 +2923,8 @@ func (ec *executionContext) fieldContext_Query_articles(ctx context.Context, fie
return fc, nil
}
func (ec *executionContext) _Query_maxBlogs(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) {
fc, err := ec.fieldContext_Query_maxBlogs(ctx, field)
func (ec *executionContext) _Query_masterParameter(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) {
fc, err := ec.fieldContext_Query_masterParameter(ctx, field)
if err != nil {
return graphql.Null
}
......@@ -2842,75 +2937,34 @@ func (ec *executionContext) _Query_maxBlogs(ctx context.Context, field graphql.C
}()
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
ctx = rctx // use context from middleware stack in children
return ec.resolvers.Query().MaxBlogs(rctx)
return ec.resolvers.Query().MasterParameter(rctx)
})
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)
res := resTmp.(*model.MasterParameter)
fc.Result = res
return ec.marshalNInt2int(ctx, field.Selections, res)
return ec.marshalOMasterParameter2ᚖgitlabᚗcomᚋk1350ᚋsololog_gqlᚋgraphᚋmodelᚐMasterParameter(ctx, field.Selections, res)
}
func (ec *executionContext) fieldContext_Query_maxBlogs(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
func (ec *executionContext) fieldContext_Query_masterParameter(ctx 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) {
return nil, errors.New("field of type Int does not have child fields")
},
}
return fc, nil
}
func (ec *executionContext) _Query_maxBlogLinks(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) {
fc, err := ec.fieldContext_Query_maxBlogLinks(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().MaxBlogLinks(rctx)
})
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_Query_maxBlogLinks(ctx 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) {
return nil, errors.New("field of type Int does not have child fields")
switch field.Name {
case "maxBlogs":
return ec.fieldContext_MasterParameter_maxBlogs(ctx, field)
case "maxBlogLinks":
return ec.fieldContext_MasterParameter_maxBlogLinks(ctx, field)
}
return nil, fmt.Errorf("no field named %q was found under type MasterParameter", field.Name)
},
}
return fc, nil
......@@ -5729,55 +5783,29 @@ func (ec *executionContext) _Article(ctx context.Context, sel ast.SelectionSet,
out.Values[i] = ec._Article_id(ctx, field, obj)
if out.Values[i] == graphql.Null {
atomic.AddUint32(&invalids, 1)
invalids++
}
case "content":
out.Values[i] = ec._Article_content(ctx, field, obj)
if out.Values[i] == graphql.Null {
atomic.AddUint32(&invalids, 1)
invalids++
}
case "createdAt":
field := field
innerFunc := func(ctx context.Context) (res graphql.Marshaler) {
defer func() {
if r := recover(); r != nil {
ec.Error(ctx, ec.Recover(ctx, r))
}
}()
res = ec._Article_createdAt(ctx, field, obj)
if res == graphql.Null {
atomic.AddUint32(&invalids, 1)
}
return res
}
out.Concurrently(i, func() graphql.Marshaler {
return innerFunc(ctx)
})
case "updatedAt":
field := field
out.Values[i] = ec._Article_createdAt(ctx, field, obj)
innerFunc := func(ctx context.Context) (res graphql.Marshaler) {
defer func() {
if r := recover(); r != nil {
ec.Error(ctx, ec.Recover(ctx, r))
}
}()
res = ec._Article_updatedAt(ctx, field, obj)
if res == graphql.Null {
atomic.AddUint32(&invalids, 1)
}
return res
if out.Values[i] == graphql.Null {
invalids++
}
case "updatedAt":
out.Concurrently(i, func() graphql.Marshaler {
return innerFunc(ctx)
out.Values[i] = ec._Article_updatedAt(ctx, field, obj)
})
if out.Values[i] == graphql.Null {
invalids++
}
default:
panic("unknown field " + strconv.Quote(field.Name))
}
......@@ -5926,45 +5954,19 @@ func (ec *executionContext) _Blog(ctx context.Context, sel ast.SelectionSet, obj
})
case "createdAt":
field := field
innerFunc := func(ctx context.Context) (res graphql.Marshaler) {
defer func() {
if r := recover(); r != nil {
ec.Error(ctx, ec.Recover(ctx, r))
}
}()
res = ec._Blog_createdAt(ctx, field, obj)
if res == graphql.Null {
atomic.AddUint32(&invalids, 1)
}
return res
}
out.Concurrently(i, func() graphql.Marshaler {
return innerFunc(ctx)
})
case "updatedAt":
field := field
out.Values[i] = ec._Blog_createdAt(ctx, field, obj)
innerFunc := func(ctx context.Context) (res graphql.Marshaler) {
defer func() {
if r := recover(); r != nil {
ec.Error(ctx, ec.Recover(ctx, r))
}
}()
res = ec._Blog_updatedAt(ctx, field, obj)
if res == graphql.Null {
atomic.AddUint32(&invalids, 1)
}
return res
if out.Values[i] == graphql.Null {
atomic.AddUint32(&invalids, 1)
}
case "updatedAt":
out.Concurrently(i, func() graphql.Marshaler {
return innerFunc(ctx)
out.Values[i] = ec._Blog_updatedAt(ctx, field, obj)
})
if out.Values[i] == graphql.Null {
atomic.AddUint32(&invalids, 1)
}
default:
panic("unknown field " + strconv.Quote(field.Name))
}
......@@ -6018,6 +6020,41 @@ func (ec *executionContext) _BlogLink(ctx context.Context, sel ast.SelectionSet,
return out
}
var masterParameterImplementors = []string{"MasterParameter"}
func (ec *executionContext) _MasterParameter(ctx context.Context, sel ast.SelectionSet, obj *model.MasterParameter) graphql.Marshaler {
fields := graphql.CollectFields(ec.OperationContext, sel, masterParameterImplementors)
out := graphql.NewFieldSet(fields)
var invalids uint32
for i, field := range fields {
switch field.Name {
case "__typename":
out.Values[i] = graphql.MarshalString("MasterParameter")
case "maxBlogs":
out.Values[i] = ec._MasterParameter_maxBlogs(ctx, field, obj)
if out.Values[i] == graphql.Null {
invalids++
}
case "maxBlogLinks":
out.Values[i] = ec._MasterParameter_maxBlogLinks(ctx, field, obj)
if out.Values[i] == graphql.Null {
invalids++
}
default:
panic("unknown field " + strconv.Quote(field.Name))
}
}
out.Dispatch()
if invalids > 0 {
return graphql.Null
}
return out
}
var mutationImplementors = []string{"Mutation"}
func (ec *executionContext) _Mutation(ctx context.Context, sel ast.SelectionSet) graphql.Marshaler {
......@@ -6261,7 +6298,7 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr
out.Concurrently(i, func() graphql.Marshaler {
return rrm(innerCtx)
})
case "maxBlogs":
case "masterParameter":
field := field
innerFunc := func(ctx context.Context) (res graphql.Marshaler) {
......@@ -6270,33 +6307,7 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr
ec.Error(ctx, ec.Recover(ctx, r))
}
}()
res = ec._Query_maxBlogs(ctx, field)
if res == graphql.Null {
atomic.AddUint32(&invalids, 1)
}
return res
}
rrm := func(ctx context.Context) graphql.Marshaler {
return ec.OperationContext.RootResolverMiddleware(ctx, innerFunc)
}
out.Concurrently(i, func() graphql.Marshaler {
return rrm(innerCtx)
})
case "maxBlogLinks":
field := field
innerFunc := func(ctx context.Context) (res graphql.Marshaler) {
defer func() {
if r := recover(); r != nil {
ec.Error(ctx, ec.Recover(ctx, r))
}
}()
res = ec._Query_maxBlogLinks(ctx, field)
if res == graphql.Null {
atomic.AddUint32(&invalids, 1)
}
res = ec._Query_masterParameter(ctx, field)
return res
}
......@@ -7276,6 +7287,13 @@ func (ec *executionContext) marshalOInt2ᚖint(ctx context.Context, sel ast.Sele
return res
}
func (ec *executionContext) marshalOMasterParameter2ᚖgitlabᚗcomᚋk1350ᚋsololog_gqlᚋgraphᚋmodelᚐMasterParameter(ctx context.Context, sel ast.SelectionSet, v *model.MasterParameter) graphql.Marshaler {