Skip to content

Commit

Permalink
add draft configurations for entity interfaces
Browse files Browse the repository at this point in the history
add rename types to datasource config
  • Loading branch information
devsergiy committed Dec 15, 2023
1 parent 49b34ba commit 4b5c178
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -944,7 +944,12 @@ func (p *Planner) addOnTypeInlineFragment() {

selectionSet := p.upstreamOperation.AddSelectionSet()
p.addTypenameToSelectionSet(p.nodes[len(p.nodes)-1].Ref)

onTypeName := p.visitor.Config.Types.RenameTypeNameOnMatchBytes([]byte(p.lastFieldEnclosingTypeName))

// rename type name in case it is required by entity interface
onTypeName = p.dataSourceConfig.RenameTypes.RenameTypeNameOnMatchBytes([]byte(p.lastFieldEnclosingTypeName))

typeRef := p.upstreamOperation.AddNamedType(onTypeName)
inlineFragment := p.upstreamOperation.AddInlineFragment(ast.InlineFragment{
HasSelections: true,
Expand Down Expand Up @@ -1449,7 +1454,7 @@ func (p *Planner) printOperation() []byte {
return nil
}

p.printQueryPlan(p.upstreamOperation)
p.printQueryPlan(operation)

buf.Reset()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,6 @@ func TestGraphQLDataSourceFederationEntityInterfaces(t *testing.T) {

firstDatasourceConfiguration := plan.DataSourceConfiguration{
RootNodes: []plan.TypeField{
{
TypeName: "Account",
FieldNames: []string{"id", "title"},
},
{
TypeName: "Admin",
FieldNames: []string{"id"},
Expand All @@ -107,6 +103,12 @@ func TestGraphQLDataSourceFederationEntityInterfaces(t *testing.T) {
FieldNames: []string{"allAccountsInterface", "allAccountsUnion", "user", "admin"},
},
},
ChildNodes: []plan.TypeField{
{
TypeName: "Account",
FieldNames: []string{"id", "title"},
},
},
Custom: ConfigJson(Configuration{
Fetch: FetchConfiguration{
URL: "http://first.service",
Expand Down Expand Up @@ -163,6 +165,18 @@ func TestGraphQLDataSourceFederationEntityInterfaces(t *testing.T) {
TypeName: "Account",
FieldNames: []string{"id", "locations"},
},
{
TypeName: "User",
FieldNames: []string{"id", "locations"},
},
{
TypeName: "Moderator",
FieldNames: []string{"id", "locations"},
},
{
TypeName: "Admin",
FieldNames: []string{"id", "locations"},
},
{
TypeName: "Query",
FieldNames: []string{"accountLocations"},
Expand Down Expand Up @@ -191,6 +205,35 @@ func TestGraphQLDataSourceFederationEntityInterfaces(t *testing.T) {
TypeName: "Account",
SelectionSet: "id",
},
{
TypeName: "Admin",
InterfaceNames: []string{"Account"},
SelectionSet: "id",
},
{
TypeName: "Moderator",
InterfaceNames: []string{"Account"},
SelectionSet: "id",
},
{
TypeName: "User",
InterfaceNames: []string{"Account"},
SelectionSet: "id",
},
},
},
RenameTypes: plan.TypeConfigurations{
{
TypeName: "Admin",
RenameTo: "Account",
},
{
TypeName: "Moderator",
RenameTo: "Account",
},
{
TypeName: "User",
RenameTo: "Account",
},
},
}
Expand Down Expand Up @@ -241,6 +284,18 @@ func TestGraphQLDataSourceFederationEntityInterfaces(t *testing.T) {
TypeName: "Account",
FieldNames: []string{"id", "age"},
},
{
TypeName: "User",
FieldNames: []string{"id", "age"},
},
{
TypeName: "Moderator",
FieldNames: []string{"id", "age"},
},
{
TypeName: "Admin",
FieldNames: []string{"id", "age"},
},
},
Custom: ConfigJson(Configuration{
Fetch: FetchConfiguration{
Expand All @@ -259,6 +314,35 @@ func TestGraphQLDataSourceFederationEntityInterfaces(t *testing.T) {
TypeName: "Account",
SelectionSet: "id",
},
{
TypeName: "Admin",
InterfaceNames: []string{"Account"},
SelectionSet: "id",
},
{
TypeName: "Moderator",
InterfaceNames: []string{"Account"},
SelectionSet: "id",
},
{
TypeName: "User",
InterfaceNames: []string{"Account"},
SelectionSet: "id",
},
},
},
RenameTypes: plan.TypeConfigurations{
{
TypeName: "Admin",
RenameTo: "Account",
},
{
TypeName: "Moderator",
RenameTo: "Account",
},
{
TypeName: "User",
RenameTo: "Account",
},
},
}
Expand All @@ -274,25 +358,33 @@ func TestGraphQLDataSourceFederationEntityInterfaces(t *testing.T) {
DataSources: ShuffleDS(dataSources),
DisableResolveFieldPositions: true,
Debug: plan.DebugConfiguration{
PrintQueryPlans: true,
PrintOperationTransformations: true,
PrintQueryPlans: true,
PrintPlanningPaths: true,
PrintNodeSuggestions: true,
},
}

t.Run("query 1 - ", func(t *testing.T) {
t.Run("query 1 - Interface to interface object", func(t *testing.T) {

t.Run("run", RunTest(
definition,
`
query {
query _1_InterfaceToInterfaceObject {
allAccountsInterface {
id
locations {
country
}
}
`,
"Accounts",
}`,
"_1_InterfaceToInterfaceObject",
&plan.SynchronousResponsePlan{
Response: &resolve.GraphQLResponse{
Data: &resolve.Object{
Fetch: &resolve.SingleFetch{
FetchConfiguration: resolve.FetchConfiguration{
Input: `{"method":"POST","url":"http://first.service","body":{"query":"{account {__typename ... on User {__typename id} ... on Admin {__typename id}}}"}}`,
Input: `{"method":"POST","url":"http://first.service","body":{"query":""}}`,
PostProcessing: DefaultPostProcessingConfiguration,
DataSource: &Source{},
},
Expand Down
1 change: 1 addition & 0 deletions v2/pkg/engine/plan/datasource_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type DataSourceConfiguration struct {
Custom json.RawMessage

FederationMetaData FederationMetaData
RenameTypes TypeConfigurations

hash DSHash
}
Expand Down

0 comments on commit 4b5c178

Please sign in to comment.