...

Source file src/edge-infra.dev/pkg/edge/api/client/examples/mutation_example.go

Documentation: edge-infra.dev/pkg/edge/api/client/examples

     1  package examples
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  	"time"
     7  
     8  	"github.com/shurcooL/graphql"
     9  
    10  	"edge-infra.dev/pkg/edge/api/client"
    11  	"edge-infra.dev/pkg/edge/api/graph/model"
    12  )
    13  
    14  func LoginMutation() {
    15  	username := "my-username"
    16  	password := ""
    17  	organization := "edge-dev1-retail-b526aa"
    18  	cl, err := client.New(client.WithTimeout(5 * time.Second))
    19  	if err != nil {
    20  		fmt.Println("err: ", err)
    21  	}
    22  	var loginMutation struct {
    23  		model.AuthPayload `graphql:"login(username: $username, password: $password, organization: $organization)"`
    24  	}
    25  	if err := cl.Mutate(context.Background(), &loginMutation, map[string]any{
    26  		"username":     graphql.String(username),
    27  		"password":     graphql.String(password),
    28  		"organization": graphql.String(organization),
    29  	}); err != nil {
    30  		fmt.Println("err: ", err)
    31  	}
    32  	fmt.Printf("Response AuthPayload: %v\n", loginMutation.AuthPayload)
    33  	fmt.Printf("Edge Cookie in cookie jar: %v\n", cl.HTTPClient.Jar.Cookies(cl.BaseURL))
    34  }
    35  

View as plain text