From e8864cb379beca848950f231b3a633ab734252e0 Mon Sep 17 00:00:00 2001 From: Allyson-English Date: Tue, 11 Jun 2024 14:42:20 -0400 Subject: [PATCH 1/6] query vehicle from synthetic device --- gqlgen.yml | 31 ++-- graph/generated.go | 158 +++++++++++++++--- graph/model/models_gen.go | 7 +- graph/schema/synthetic.graphqls | 4 + graph/synthetic.resolvers.go | 14 ++ .../synthetic/synthetic_devices.go | 11 +- .../synthetic/synthetic_devices_test.go | 1 + 7 files changed, 181 insertions(+), 45 deletions(-) diff --git a/gqlgen.yml b/gqlgen.yml index 680084b9..7ab7a70b 100644 --- a/gqlgen.yml +++ b/gqlgen.yml @@ -22,7 +22,7 @@ resolver: layout: follow-schema dir: graph package: graph - filename_template: "{name}.resolvers.go" + filename_template: '{name}.resolvers.go' # Optional: turn on to not generate template comments above resolvers # omit_template_comment: false @@ -66,7 +66,7 @@ resolver: # gqlgen will search for any type names in the schema in these go packages # if they match it will use them, otherwise it will generate them. autobind: - - "github.com/DIMO-Network/identity-api/graph/model" + - 'github.com/DIMO-Network/identity-api/graph/model' # This section declares type mapping between the GraphQL and go type systems # @@ -107,7 +107,7 @@ models: resolver: true extraFields: VehicleID: - type: "*int" + type: '*int' AftermarketDevice: fields: vehicle: @@ -118,9 +118,16 @@ models: resolver: true extraFields: VehicleID: - type: "*int" + type: '*int' ManufacturerID: - type: "int" + type: 'int' + SyntheticDevice: + fields: + vehicle: + resolver: true + extraFields: + VehicleID: + type: '*int' Vehicle: fields: manufacturer: @@ -137,28 +144,28 @@ models: resolver: true extraFields: ManufacturerID: - type: "int" + type: 'int' VehicleEarnings: fields: history: resolver: true extraFields: VehicleID: - type: "int" + type: 'int' AftermarketDeviceEarnings: fields: history: resolver: true extraFields: AftermarketDeviceID: - type: "int" + type: 'int' UserRewards: fields: history: resolver: true extraFields: User: - type: "github.com/ethereum/go-ethereum/common.Address" + type: 'github.com/ethereum/go-ethereum/common.Address' Earning: fields: aftermarketDevice: @@ -169,8 +176,8 @@ models: resolver: true extraFields: AftermarketDeviceID: - type: "*int" + type: '*int' SyntheticDeviceID: - type: "*int" + type: '*int' VehicleID: - type: "int" + type: 'int' diff --git a/graph/generated.go b/graph/generated.go index b59d0fed..dd9ca769 100644 --- a/graph/generated.go +++ b/graph/generated.go @@ -50,6 +50,7 @@ type ResolverRoot interface { Earning() EarningResolver Manufacturer() ManufacturerResolver Query() QueryResolver + SyntheticDevice() SyntheticDeviceResolver UserRewards() UserRewardsResolver Vehicle() VehicleResolver VehicleEarnings() VehicleEarningsResolver @@ -236,6 +237,7 @@ type ComplexityRoot struct { MintedAt func(childComplexity int) int Name func(childComplexity int) int TokenID func(childComplexity int) int + Vehicle func(childComplexity int) int } SyntheticDeviceConnection struct { @@ -329,6 +331,9 @@ type QueryResolver interface { Vehicle(ctx context.Context, tokenID int) (*model.Vehicle, error) Vehicles(ctx context.Context, first *int, after *string, last *int, before *string, filterBy *model.VehiclesFilter) (*model.VehicleConnection, error) } +type SyntheticDeviceResolver interface { + Vehicle(ctx context.Context, obj *model.SyntheticDevice) (*model.Vehicle, error) +} type UserRewardsResolver interface { History(ctx context.Context, obj *model.UserRewards, first *int, after *string, last *int, before *string) (*model.EarningsConnection, error) } @@ -1225,6 +1230,13 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.SyntheticDevice.TokenID(childComplexity), true + case "SyntheticDevice.vehicle": + if e.complexity.SyntheticDevice.Vehicle == nil { + break + } + + return e.complexity.SyntheticDevice.Vehicle(childComplexity), true + case "SyntheticDeviceConnection.edges": if e.complexity.SyntheticDeviceConnection.Edges == nil { break @@ -5290,6 +5302,8 @@ func (ec *executionContext) fieldContext_Earning_syntheticDevice(_ context.Conte return ec.fieldContext_SyntheticDevice_address(ctx, field) case "mintedAt": return ec.fieldContext_SyntheticDevice_mintedAt(ctx, field) + case "vehicle": + return ec.fieldContext_SyntheticDevice_vehicle(ctx, field) } return nil, fmt.Errorf("no field named %q was found under type SyntheticDevice", field.Name) }, @@ -7414,6 +7428,8 @@ func (ec *executionContext) fieldContext_Query_syntheticDevice(ctx context.Conte return ec.fieldContext_SyntheticDevice_address(ctx, field) case "mintedAt": return ec.fieldContext_SyntheticDevice_mintedAt(ctx, field) + case "vehicle": + return ec.fieldContext_SyntheticDevice_vehicle(ctx, field) } return nil, fmt.Errorf("no field named %q was found under type SyntheticDevice", field.Name) }, @@ -8042,6 +8058,79 @@ func (ec *executionContext) fieldContext_SyntheticDevice_mintedAt(_ context.Cont return fc, nil } +func (ec *executionContext) _SyntheticDevice_vehicle(ctx context.Context, field graphql.CollectedField, obj *model.SyntheticDevice) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_SyntheticDevice_vehicle(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.SyntheticDevice().Vehicle(rctx, obj) + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*model.Vehicle) + fc.Result = res + return ec.marshalOVehicle2ᚖgithubᚗcomᚋDIMOᚑNetworkᚋidentityᚑapiᚋgraphᚋmodelᚐVehicle(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_SyntheticDevice_vehicle(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "SyntheticDevice", + Field: field, + IsMethod: true, + IsResolver: true, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "id": + return ec.fieldContext_Vehicle_id(ctx, field) + case "tokenId": + return ec.fieldContext_Vehicle_tokenId(ctx, field) + case "manufacturer": + return ec.fieldContext_Vehicle_manufacturer(ctx, field) + case "owner": + return ec.fieldContext_Vehicle_owner(ctx, field) + case "mintedAt": + return ec.fieldContext_Vehicle_mintedAt(ctx, field) + case "aftermarketDevice": + return ec.fieldContext_Vehicle_aftermarketDevice(ctx, field) + case "privileges": + return ec.fieldContext_Vehicle_privileges(ctx, field) + case "syntheticDevice": + return ec.fieldContext_Vehicle_syntheticDevice(ctx, field) + case "definition": + return ec.fieldContext_Vehicle_definition(ctx, field) + case "dcn": + return ec.fieldContext_Vehicle_dcn(ctx, field) + case "name": + return ec.fieldContext_Vehicle_name(ctx, field) + case "imageURI": + return ec.fieldContext_Vehicle_imageURI(ctx, field) + case "image": + return ec.fieldContext_Vehicle_image(ctx, field) + case "earnings": + return ec.fieldContext_Vehicle_earnings(ctx, field) + case "dataURI": + return ec.fieldContext_Vehicle_dataURI(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type Vehicle", field.Name) + }, + } + return fc, nil +} + func (ec *executionContext) _SyntheticDeviceConnection_totalCount(ctx context.Context, field graphql.CollectedField, obj *model.SyntheticDeviceConnection) (ret graphql.Marshaler) { fc, err := ec.fieldContext_SyntheticDeviceConnection_totalCount(ctx, field) if err != nil { @@ -8187,6 +8276,8 @@ func (ec *executionContext) fieldContext_SyntheticDeviceConnection_nodes(_ conte return ec.fieldContext_SyntheticDevice_address(ctx, field) case "mintedAt": return ec.fieldContext_SyntheticDevice_mintedAt(ctx, field) + case "vehicle": + return ec.fieldContext_SyntheticDevice_vehicle(ctx, field) } return nil, fmt.Errorf("no field named %q was found under type SyntheticDevice", field.Name) }, @@ -8343,6 +8434,8 @@ func (ec *executionContext) fieldContext_SyntheticDeviceEdge_node(_ context.Cont return ec.fieldContext_SyntheticDevice_address(ctx, field) case "mintedAt": return ec.fieldContext_SyntheticDevice_mintedAt(ctx, field) + case "vehicle": + return ec.fieldContext_SyntheticDevice_vehicle(ctx, field) } return nil, fmt.Errorf("no field named %q was found under type SyntheticDevice", field.Name) }, @@ -8883,6 +8976,8 @@ func (ec *executionContext) fieldContext_Vehicle_syntheticDevice(_ context.Conte return ec.fieldContext_SyntheticDevice_address(ctx, field) case "mintedAt": return ec.fieldContext_SyntheticDevice_mintedAt(ctx, field) + case "vehicle": + return ec.fieldContext_SyntheticDevice_vehicle(ctx, field) } return nil, fmt.Errorf("no field named %q was found under type SyntheticDevice", field.Name) }, @@ -11716,27 +11811,13 @@ func (ec *executionContext) unmarshalInputDeviceDefinitionFilter(ctx context.Con asMap[k] = v } - fieldsInOrder := [...]string{"manufacturer", "id", "model", "year"} + fieldsInOrder := [...]string{"model", "year"} for _, k := range fieldsInOrder { v, ok := asMap[k] if !ok { continue } switch k { - case "manufacturer": - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("manufacturer")) - data, err := ec.unmarshalNString2string(ctx, v) - if err != nil { - return it, err - } - it.Manufacturer = data - case "id": - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("id")) - data, err := ec.unmarshalOString2ᚖstring(ctx, v) - if err != nil { - return it, err - } - it.ID = data case "model": ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("model")) data, err := ec.unmarshalOString2ᚖstring(ctx, v) @@ -12005,8 +12086,6 @@ func (ec *executionContext) unmarshalInputVehiclesFilter(ctx context.Context, ob } it.Year = data case "manufacturerTokenId": - var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("manufacturerTokenId")) data, err := ec.unmarshalOInt2ᚖint(ctx, v) if err != nil { @@ -13784,33 +13863,66 @@ func (ec *executionContext) _SyntheticDevice(ctx context.Context, sel ast.Select case "id": out.Values[i] = ec._SyntheticDevice_id(ctx, field, obj) if out.Values[i] == graphql.Null { - out.Invalids++ + atomic.AddUint32(&out.Invalids, 1) } case "name": out.Values[i] = ec._SyntheticDevice_name(ctx, field, obj) if out.Values[i] == graphql.Null { - out.Invalids++ + atomic.AddUint32(&out.Invalids, 1) } case "tokenId": out.Values[i] = ec._SyntheticDevice_tokenId(ctx, field, obj) if out.Values[i] == graphql.Null { - out.Invalids++ + atomic.AddUint32(&out.Invalids, 1) } case "integrationId": out.Values[i] = ec._SyntheticDevice_integrationId(ctx, field, obj) if out.Values[i] == graphql.Null { - out.Invalids++ + atomic.AddUint32(&out.Invalids, 1) } case "address": out.Values[i] = ec._SyntheticDevice_address(ctx, field, obj) if out.Values[i] == graphql.Null { - out.Invalids++ + atomic.AddUint32(&out.Invalids, 1) } case "mintedAt": out.Values[i] = ec._SyntheticDevice_mintedAt(ctx, field, obj) if out.Values[i] == graphql.Null { - out.Invalids++ + atomic.AddUint32(&out.Invalids, 1) } + case "vehicle": + field := field + + innerFunc := func(ctx context.Context, _ *graphql.FieldSet) (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._SyntheticDevice_vehicle(ctx, field, obj) + return res + } + + if field.Deferrable != nil { + dfs, ok := deferred[field.Deferrable.Label] + di := 0 + if ok { + dfs.AddField(field) + di = len(dfs.Values) - 1 + } else { + dfs = graphql.NewFieldSet([]graphql.CollectedField{field}) + deferred[field.Deferrable.Label] = dfs + } + dfs.Concurrently(di, func(ctx context.Context) graphql.Marshaler { + return innerFunc(ctx, dfs) + }) + + // don't run the out.Concurrently() call below + out.Values[i] = graphql.Null + continue + } + + out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return innerFunc(ctx, out) }) default: panic("unknown field " + strconv.Quote(field.Name)) } diff --git a/graph/model/models_gen.go b/graph/model/models_gen.go index 2eafe735..619d3371 100644 --- a/graph/model/models_gen.go +++ b/graph/model/models_gen.go @@ -207,10 +207,6 @@ type DeviceDefinitionEdge struct { // Filter for Device Definition. type DeviceDefinitionFilter struct { - // The manufacturer for the device definition. - Manufacturer string `json:"manufacturer"` - // ID filters for the device definition that are of the given model. - ID *string `json:"id,omitempty"` // Model filters for device definition that are of the given model. Model *string `json:"model,omitempty"` // Year filters for device definition that are of the given year. @@ -336,6 +332,9 @@ type SyntheticDevice struct { Address common.Address `json:"address"` // The block timestamp at which this device was minted. MintedAt time.Time `json:"mintedAt"` + // The vehicle, if any, with which the synthetic device is paired. + Vehicle *Vehicle `json:"vehicle,omitempty"` + VehicleID *int `json:"-"` } func (SyntheticDevice) IsNode() {} diff --git a/graph/schema/synthetic.graphqls b/graph/schema/synthetic.graphqls index f82c29aa..c19f42f2 100644 --- a/graph/schema/synthetic.graphqls +++ b/graph/schema/synthetic.graphqls @@ -64,6 +64,10 @@ type SyntheticDevice implements Node { The block timestamp at which this device was minted. """ mintedAt: Time! + """ + The vehicle, if any, with which the synthetic device is paired. + """ + vehicle: Vehicle } """ diff --git a/graph/synthetic.resolvers.go b/graph/synthetic.resolvers.go index 225f15e3..d217c0ae 100644 --- a/graph/synthetic.resolvers.go +++ b/graph/synthetic.resolvers.go @@ -8,6 +8,7 @@ import ( "context" "github.com/DIMO-Network/identity-api/graph/model" + "github.com/DIMO-Network/identity-api/internal/loader" ) // SyntheticDevice is the resolver for the syntheticDevice field. @@ -19,3 +20,16 @@ func (r *queryResolver) SyntheticDevice(ctx context.Context, by model.SyntheticD func (r *queryResolver) SyntheticDevices(ctx context.Context, first *int, last *int, after *string, before *string, filterBy *model.SyntheticDevicesFilter) (*model.SyntheticDeviceConnection, error) { return r.synthetic.GetSyntheticDevices(ctx, first, last, after, before, filterBy) } + +// Vehicle is the resolver for the vehicle field. +func (r *syntheticDeviceResolver) Vehicle(ctx context.Context, obj *model.SyntheticDevice) (*model.Vehicle, error) { + if obj.VehicleID == nil { + return nil, nil + } + return loader.GetVehicleByID(ctx, *obj.VehicleID) +} + +// SyntheticDevice returns SyntheticDeviceResolver implementation. +func (r *Resolver) SyntheticDevice() SyntheticDeviceResolver { return &syntheticDeviceResolver{r} } + +type syntheticDeviceResolver struct{ *Resolver } diff --git a/internal/repositories/synthetic/synthetic_devices.go b/internal/repositories/synthetic/synthetic_devices.go index 7b556d5c..6037900f 100644 --- a/internal/repositories/synthetic/synthetic_devices.go +++ b/internal/repositories/synthetic/synthetic_devices.go @@ -43,6 +43,7 @@ func ToAPI(sd *models.SyntheticDevice) (*gmodel.SyntheticDevice, error) { IntegrationID: sd.IntegrationID, Address: common.BytesToAddress(sd.DeviceAddress), MintedAt: sd.MintedAt, + VehicleID: &sd.VehicleID, }, nil } @@ -91,9 +92,7 @@ func (r *Repository) GetSyntheticDevices(ctx context.Context, first *int, last * return nil, fmt.Errorf("invalid after cursor: %w", err) } queryMods = append(queryMods, models.SyntheticDeviceWhere.ID.LT(afterID)) - } - - if before != nil { + } else if before != nil { beforeID, err := helpers.CursorToID(*before) if err != nil { return nil, fmt.Errorf("invalid before cursor: %w", err) @@ -101,15 +100,15 @@ func (r *Repository) GetSyntheticDevices(ctx context.Context, first *int, last * queryMods = append(queryMods, models.SyntheticDeviceWhere.ID.GT(beforeID)) } - orderBy := "DESC" + orderBy := " DESC" if last != nil { - orderBy = "ASC" + orderBy = " ASC" } queryMods = append(queryMods, // Use limit + 1 here to check if there's another page. qm.Limit(limit+1), - qm.OrderBy(models.SyntheticDeviceColumns.ID+" "+orderBy), + qm.OrderBy(models.SyntheticDeviceColumns.ID+orderBy), ) all, err := models.SyntheticDevices(queryMods...).All(ctx, r.PDB.DBS().Reader) diff --git a/internal/repositories/synthetic/synthetic_devices_test.go b/internal/repositories/synthetic/synthetic_devices_test.go index 255a3721..3691b920 100644 --- a/internal/repositories/synthetic/synthetic_devices_test.go +++ b/internal/repositories/synthetic/synthetic_devices_test.go @@ -59,6 +59,7 @@ func Test_SyntheticDeviceToAPI(t *testing.T) { IntegrationID: 2, Address: *wallet, MintedAt: currTime, + VehicleID: &sd.VehicleID, }, res) } From c85b600fbaae90b54234447725b9055fe8a282f5 Mon Sep 17 00:00:00 2001 From: Allyson-English Date: Mon, 17 Jun 2024 16:49:10 -0400 Subject: [PATCH 2/6] clean up --- gqlgen.yml | 26 +++++++++---------- graph/schema/synthetic.graphqls | 2 +- .../synthetic/synthetic_devices.go | 4 ++- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/gqlgen.yml b/gqlgen.yml index 7ab7a70b..09c819d8 100644 --- a/gqlgen.yml +++ b/gqlgen.yml @@ -22,7 +22,7 @@ resolver: layout: follow-schema dir: graph package: graph - filename_template: '{name}.resolvers.go' + filename_template: "{name}.resolvers.go" # Optional: turn on to not generate template comments above resolvers # omit_template_comment: false @@ -66,7 +66,7 @@ resolver: # gqlgen will search for any type names in the schema in these go packages # if they match it will use them, otherwise it will generate them. autobind: - - 'github.com/DIMO-Network/identity-api/graph/model' + - "github.com/DIMO-Network/identity-api/graph/model" # This section declares type mapping between the GraphQL and go type systems # @@ -107,7 +107,7 @@ models: resolver: true extraFields: VehicleID: - type: '*int' + type: "*int" AftermarketDevice: fields: vehicle: @@ -118,16 +118,16 @@ models: resolver: true extraFields: VehicleID: - type: '*int' + type: "*int" ManufacturerID: - type: 'int' + type: "int" SyntheticDevice: fields: vehicle: resolver: true extraFields: VehicleID: - type: '*int' + type: "int" Vehicle: fields: manufacturer: @@ -144,28 +144,28 @@ models: resolver: true extraFields: ManufacturerID: - type: 'int' + type: "int" VehicleEarnings: fields: history: resolver: true extraFields: VehicleID: - type: 'int' + type: "int" AftermarketDeviceEarnings: fields: history: resolver: true extraFields: AftermarketDeviceID: - type: 'int' + type: "int" UserRewards: fields: history: resolver: true extraFields: User: - type: 'github.com/ethereum/go-ethereum/common.Address' + type: "github.com/ethereum/go-ethereum/common.Address" Earning: fields: aftermarketDevice: @@ -176,8 +176,8 @@ models: resolver: true extraFields: AftermarketDeviceID: - type: '*int' + type: "*int" SyntheticDeviceID: - type: '*int' + type: "*int" VehicleID: - type: 'int' + type: "int" diff --git a/graph/schema/synthetic.graphqls b/graph/schema/synthetic.graphqls index c19f42f2..4ed971ae 100644 --- a/graph/schema/synthetic.graphqls +++ b/graph/schema/synthetic.graphqls @@ -67,7 +67,7 @@ type SyntheticDevice implements Node { """ The vehicle, if any, with which the synthetic device is paired. """ - vehicle: Vehicle + vehicle: Vehicle! } """ diff --git a/internal/repositories/synthetic/synthetic_devices.go b/internal/repositories/synthetic/synthetic_devices.go index 6037900f..0270bc3f 100644 --- a/internal/repositories/synthetic/synthetic_devices.go +++ b/internal/repositories/synthetic/synthetic_devices.go @@ -92,7 +92,9 @@ func (r *Repository) GetSyntheticDevices(ctx context.Context, first *int, last * return nil, fmt.Errorf("invalid after cursor: %w", err) } queryMods = append(queryMods, models.SyntheticDeviceWhere.ID.LT(afterID)) - } else if before != nil { + } + + if before != nil { beforeID, err := helpers.CursorToID(*before) if err != nil { return nil, fmt.Errorf("invalid before cursor: %w", err) From 2bc495fc70e6ec481c3b657b332dd5d62a19496a Mon Sep 17 00:00:00 2001 From: Allyson-English Date: Mon, 17 Jun 2024 17:02:41 -0400 Subject: [PATCH 3/6] not a pointer --- graph/generated.go | 10 ++++++++-- graph/model/models_gen.go | 4 ++-- internal/repositories/synthetic/synthetic_devices.go | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/graph/generated.go b/graph/generated.go index dd9ca769..7571d9a7 100644 --- a/graph/generated.go +++ b/graph/generated.go @@ -8079,11 +8079,14 @@ func (ec *executionContext) _SyntheticDevice_vehicle(ctx context.Context, field return graphql.Null } if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(*model.Vehicle) fc.Result = res - return ec.marshalOVehicle2ᚖgithubᚗcomᚋDIMOᚑNetworkᚋidentityᚑapiᚋgraphᚋmodelᚐVehicle(ctx, field.Selections, res) + return ec.marshalNVehicle2ᚖgithubᚗcomᚋDIMOᚑNetworkᚋidentityᚑapiᚋgraphᚋmodelᚐVehicle(ctx, field.Selections, res) } func (ec *executionContext) fieldContext_SyntheticDevice_vehicle(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { @@ -13893,13 +13896,16 @@ func (ec *executionContext) _SyntheticDevice(ctx context.Context, sel ast.Select case "vehicle": field := field - innerFunc := func(ctx context.Context, _ *graphql.FieldSet) (res graphql.Marshaler) { + innerFunc := func(ctx context.Context, fs *graphql.FieldSet) (res graphql.Marshaler) { defer func() { if r := recover(); r != nil { ec.Error(ctx, ec.Recover(ctx, r)) } }() res = ec._SyntheticDevice_vehicle(ctx, field, obj) + if res == graphql.Null { + atomic.AddUint32(&fs.Invalids, 1) + } return res } diff --git a/graph/model/models_gen.go b/graph/model/models_gen.go index 619d3371..187d6000 100644 --- a/graph/model/models_gen.go +++ b/graph/model/models_gen.go @@ -333,8 +333,8 @@ type SyntheticDevice struct { // The block timestamp at which this device was minted. MintedAt time.Time `json:"mintedAt"` // The vehicle, if any, with which the synthetic device is paired. - Vehicle *Vehicle `json:"vehicle,omitempty"` - VehicleID *int `json:"-"` + Vehicle *Vehicle `json:"vehicle"` + VehicleID int `json:"-"` } func (SyntheticDevice) IsNode() {} diff --git a/internal/repositories/synthetic/synthetic_devices.go b/internal/repositories/synthetic/synthetic_devices.go index 0270bc3f..96398a9c 100644 --- a/internal/repositories/synthetic/synthetic_devices.go +++ b/internal/repositories/synthetic/synthetic_devices.go @@ -43,7 +43,7 @@ func ToAPI(sd *models.SyntheticDevice) (*gmodel.SyntheticDevice, error) { IntegrationID: sd.IntegrationID, Address: common.BytesToAddress(sd.DeviceAddress), MintedAt: sd.MintedAt, - VehicleID: &sd.VehicleID, + VehicleID: sd.VehicleID, }, nil } From 995413cab467686360988d0f4b221f7a193d7e3e Mon Sep 17 00:00:00 2001 From: Allyson-English Date: Mon, 17 Jun 2024 17:05:59 -0400 Subject: [PATCH 4/6] not a pointer prt 2 --- graph/synthetic.resolvers.go | 5 +---- internal/repositories/synthetic/synthetic_devices_test.go | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/graph/synthetic.resolvers.go b/graph/synthetic.resolvers.go index d217c0ae..cbb7cc54 100644 --- a/graph/synthetic.resolvers.go +++ b/graph/synthetic.resolvers.go @@ -23,10 +23,7 @@ func (r *queryResolver) SyntheticDevices(ctx context.Context, first *int, last * // Vehicle is the resolver for the vehicle field. func (r *syntheticDeviceResolver) Vehicle(ctx context.Context, obj *model.SyntheticDevice) (*model.Vehicle, error) { - if obj.VehicleID == nil { - return nil, nil - } - return loader.GetVehicleByID(ctx, *obj.VehicleID) + return loader.GetVehicleByID(ctx, obj.VehicleID) } // SyntheticDevice returns SyntheticDeviceResolver implementation. diff --git a/internal/repositories/synthetic/synthetic_devices_test.go b/internal/repositories/synthetic/synthetic_devices_test.go index 3691b920..45d898ae 100644 --- a/internal/repositories/synthetic/synthetic_devices_test.go +++ b/internal/repositories/synthetic/synthetic_devices_test.go @@ -59,7 +59,7 @@ func Test_SyntheticDeviceToAPI(t *testing.T) { IntegrationID: 2, Address: *wallet, MintedAt: currTime, - VehicleID: &sd.VehicleID, + VehicleID: sd.VehicleID, }, res) } From d59ed62a1e22a818141291de22457109d23538d0 Mon Sep 17 00:00:00 2001 From: Allyson-English Date: Mon, 17 Jun 2024 17:10:13 -0400 Subject: [PATCH 5/6] update comment --- graph/model/models_gen.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/graph/model/models_gen.go b/graph/model/models_gen.go index 187d6000..718b2c76 100644 --- a/graph/model/models_gen.go +++ b/graph/model/models_gen.go @@ -332,7 +332,7 @@ type SyntheticDevice struct { Address common.Address `json:"address"` // The block timestamp at which this device was minted. MintedAt time.Time `json:"mintedAt"` - // The vehicle, if any, with which the synthetic device is paired. + // The vehicle with which the synthetic device is paired. Vehicle *Vehicle `json:"vehicle"` VehicleID int `json:"-"` } From 12eec6c547fbfb9e8af9ab22cabda6e31e74b861 Mon Sep 17 00:00:00 2001 From: Dylan Moreland Date: Mon, 17 Jun 2024 17:11:29 -0400 Subject: [PATCH 6/6] Edit vehicle link doc --- graph/schema/synthetic.graphqls | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/graph/schema/synthetic.graphqls b/graph/schema/synthetic.graphqls index 4ed971ae..0ed59ba7 100644 --- a/graph/schema/synthetic.graphqls +++ b/graph/schema/synthetic.graphqls @@ -65,7 +65,7 @@ type SyntheticDevice implements Node { """ mintedAt: Time! """ - The vehicle, if any, with which the synthetic device is paired. + The vehicle with which the synthetic device is paired. """ vehicle: Vehicle! }