thunder icon indicating copy to clipboard operation
thunder copied to clipboard

Json and non standard Scalar types

Open lantos1618 opened this issue 2 years ago • 0 comments

Hi how can you specify tables/maps?

panic: bad method dockerContainers on type schemabuilder.query: bad field labels on type types.Container: bad type map[string]string: should be a scalar, slice, or struct type

I have tried graphql:",json" but throws null pointer exception.


type Container struct {
	ID         string `json:"Id"`
	Names      []string
	Image      string
	ImageID    string
	Command    string
	Created    int64
	Ports      []Port
	SizeRw     int64             `json:",omitempty"`
	SizeRootFs int64             `json:",omitempty"`
	Labels     map[string]string
	State      string
	Status     string
	HostConfig struct {
		NetworkMode string `json:",omitempty"`
	} 
	NetworkSettings *SummaryNetworkSettings 
	Mounts          []MountPoint            
}


func (s *server) registerGetDockerContainers(schema *schemabuilder.Schema) {
	obj := schema.Query()
	obj.FieldFunc("dockerContainers", func() []types.Container {
		ctx := context.Background()
		cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
		if err != nil {
			panic(err)
		}
		containers, err := cli.ContainerList(ctx, types.ContainerListOptions{})
		if err != nil {
			panic(err)
		}
		return containers
	})
}


lantos1618 avatar Jul 07 '22 09:07 lantos1618