code.vegaprotocol.io/vega@v0.79.0/datanode/gateway/graphql/data_source_resolver.go (about)

     1  // Copyright (C) 2023 Gobalsky Labs Limited
     2  //
     3  // This program is free software: you can redistribute it and/or modify
     4  // it under the terms of the GNU Affero General Public License as
     5  // published by the Free Software Foundation, either version 3 of the
     6  // License, or (at your option) any later version.
     7  //
     8  // This program is distributed in the hope that it will be useful,
     9  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    10  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    11  // GNU Affero General Public License for more details.
    12  //
    13  // You should have received a copy of the GNU Affero General Public License
    14  // along with this program.  If not, see <http://www.gnu.org/licenses/>.
    15  
    16  package gql
    17  
    18  import (
    19  	"context"
    20  
    21  	vegapb "code.vegaprotocol.io/vega/protos/vega"
    22  )
    23  
    24  type myDataSourceDefinitionResolver VegaResolverRoot
    25  
    26  func (d myDataSourceDefinitionResolver) SourceType(_ context.Context, obj *vegapb.DataSourceDefinition) (DataSourceKind, error) {
    27  	if obj != nil {
    28  		if obj.SourceType != nil {
    29  			switch dp := obj.SourceType.(type) {
    30  			case *vegapb.DataSourceDefinition_External:
    31  				if dp.External.SourceType != nil {
    32  					return dp.External, nil
    33  				}
    34  			case *vegapb.DataSourceDefinition_Internal:
    35  				if dp.Internal.SourceType != nil {
    36  					return dp.Internal, nil
    37  				}
    38  			}
    39  		}
    40  	}
    41  
    42  	return nil, nil
    43  }
    44  
    45  type myDataSourceDefinitionExternalResolver VegaResolverRoot
    46  
    47  func (de myDataSourceDefinitionExternalResolver) SourceType(_ context.Context, obj *vegapb.DataSourceDefinitionExternal) (ExternalDataSourceKind, error) {
    48  	if obj != nil {
    49  		if obj.SourceType != nil {
    50  			switch tp := obj.SourceType.(type) {
    51  			case *vegapb.DataSourceDefinitionExternal_Oracle:
    52  				if tp.Oracle != nil {
    53  					return tp.Oracle, nil
    54  				}
    55  			case *vegapb.DataSourceDefinitionExternal_EthOracle:
    56  				if tp.EthOracle != nil {
    57  					return tp.EthOracle, nil
    58  				}
    59  			}
    60  		}
    61  	}
    62  
    63  	return nil, nil
    64  }
    65  
    66  type myDataSourceDefinitionInternalResolver VegaResolverRoot
    67  
    68  func (di myDataSourceDefinitionInternalResolver) SourceType(_ context.Context, obj *vegapb.DataSourceDefinitionInternal) (InternalDataSourceKind, error) {
    69  	if obj != nil {
    70  		if obj.SourceType != nil {
    71  			switch tp := obj.SourceType.(type) {
    72  			case *vegapb.DataSourceDefinitionInternal_Time:
    73  				if tp.Time != nil {
    74  					return tp.Time, nil
    75  				}
    76  			case *vegapb.DataSourceDefinitionInternal_TimeTrigger:
    77  				if tp.TimeTrigger != nil {
    78  					return tp.TimeTrigger, nil
    79  				}
    80  			}
    81  		}
    82  	}
    83  
    84  	return &vegapb.DataSourceSpecConfigurationTime{}, nil
    85  }