github.com/weaviate/weaviate@v1.24.6/adapters/handlers/graphql/local/get/get.go (about)

     1  //                           _       _
     2  // __      _____  __ ___   ___  __ _| |_ ___
     3  // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
     4  //  \ V  V /  __/ (_| |\ V /| | (_| | ||  __/
     5  //   \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
     6  //
     7  //  Copyright © 2016 - 2024 Weaviate B.V. All rights reserved.
     8  //
     9  //  CONTACT: hello@weaviate.io
    10  //
    11  
    12  package get
    13  
    14  import (
    15  	"github.com/sirupsen/logrus"
    16  	"github.com/tailor-inc/graphql"
    17  	"github.com/tailor-inc/graphql/language/ast"
    18  	"github.com/weaviate/weaviate/adapters/handlers/graphql/descriptions"
    19  	"github.com/weaviate/weaviate/adapters/handlers/graphql/utils"
    20  	"github.com/weaviate/weaviate/entities/models"
    21  	"github.com/weaviate/weaviate/entities/modulecapabilities"
    22  	"github.com/weaviate/weaviate/entities/schema"
    23  )
    24  
    25  type ModulesProvider interface {
    26  	GetArguments(class *models.Class) map[string]*graphql.ArgumentConfig
    27  	ExtractSearchParams(arguments map[string]interface{}, className string) map[string]interface{}
    28  	GetAdditionalFields(class *models.Class) map[string]*graphql.Field
    29  	ExtractAdditionalField(className, name string, params []*ast.Argument) interface{}
    30  	GraphQLAdditionalFieldNames() []string
    31  	GetAll() []modulecapabilities.Module
    32  }
    33  
    34  // Build the Local.Get part of the graphql tree
    35  func Build(schema *schema.Schema, logger logrus.FieldLogger,
    36  	modulesProvider ModulesProvider,
    37  ) (*graphql.Field, error) {
    38  	if len(schema.Objects.Classes) == 0 {
    39  		return nil, utils.ErrEmptySchema
    40  	}
    41  
    42  	cb := newClassBuilder(schema, logger, modulesProvider)
    43  
    44  	var err error
    45  	var objects *graphql.Object
    46  	if len(schema.Objects.Classes) > 0 {
    47  		objects, err = cb.objects()
    48  		if err != nil {
    49  			return nil, err
    50  		}
    51  	}
    52  
    53  	return &graphql.Field{
    54  		Name:        "Get",
    55  		Description: descriptions.GetObjects,
    56  		Type:        objects,
    57  		Resolve: func(p graphql.ResolveParams) (interface{}, error) {
    58  			// Does nothing; pass through the filters
    59  			return p.Source, nil
    60  		},
    61  	}, nil
    62  }