Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs: Update SayHello Function Example in Ignite Documentation to to Align with Latest Ignite #4142

Closed
hiroyukikumazawa opened this issue May 14, 2024 · 1 comment

Comments

@hiroyukikumazawa
Copy link
Contributor

Description

The example provided in the Ignite documentation for customizing the query response (located here) uses an older version of the SayHello function in the x/hello/keeper/query_say_hello.go file. A recent review of the source code shows modifications that should be reflected in the documentation to ensure it stays current and useful for developers.

Old Version

package keeper

import (
    "context"
    "fmt"

    sdk "github.com/cosmos/cosmos-sdk/types"
    "google.golang.org/grpc/codes"
    "google.golang.org/grpc/status"

    "hello/x/hello/types"
)

func (k Keeper) SayHello(goCtx context.Context, req *types.QuerySayHelloRequest) (*types.QuerySayHelloResponse, error) {
    if req == nil {
        return nil, status.Error(codes.InvalidArgument, "invalid request")
    }

    // Validation and Context unwrapping
    ctx := sdk.UnwrapSDKContext(goCtx)

    _ = ctx
    // Custom Response
    return &types.QuerySayHelloResponse{Name: fmt.Sprintf("Hello %s!", req.Name)}, nil
}

New Version

package keeper

import (
	"context"
	"fmt"

	"hello/x/hello/types"

	sdk "github.com/cosmos/cosmos-sdk/types"
	"google.golang.org/grpc/codes"
	"google.golang.org/grpc/status"
)

func (q queryServer) SayHello(ctx context.Context, req *types.QuerySayHelloRequest) (*types.QuerySayHelloResponse, error) {
	if req == nil {
		return nil, status.Error(codes.InvalidArgument, "invalid request")
	}

	// Validation and Context unwrapping
	sdkCtx := sdk.UnwrapSDKContext(ctx)

	_ = sdkCtx
	// Custom Response
	return &types.QuerySayHelloResponse{Name: fmt.Sprintf("Hello %s!", req.Name)}, nil
}

Suggested Update for Documentation

It would be beneficial for the documentation to be updated to reflect the changes in the source code. This ensures that new developers using the Ignite framework can have accurate examples that match the codebase they are working with.

Additionally, adding a brief explanation about the reason behind these changes (if applicable) might help developers understand the evolution of the code structure in Ignite.

@hiroyukikumazawa
Copy link
Contributor Author

hiroyukikumazawa commented May 14, 2024

Here is the default file of the latest version.

package keeper

import (
	"context"

	"hello/x/hello/types"

	"google.golang.org/grpc/codes"
	"google.golang.org/grpc/status"
)

func (q queryServer) SayHello(ctx context.Context, req *types.QuerySayHelloRequest) (*types.QuerySayHelloResponse, error) {
	if req == nil {
		return nil, status.Error(codes.InvalidArgument, "invalid request")
	}

	// TODO: Process the query

	return &types.QuerySayHelloResponse{}, nil
}

@salmad3 salmad3 closed this as completed May 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

No branches or pull requests

2 participants