Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public static class SchemaFormatter
new()
{
Indented = true,
MaxDirectivesPerLine = 0
PrintWidth = 80
};

public static string FormatAsString(
Expand Down
5 changes: 5 additions & 0 deletions src/HotChocolate/Fusion/src/Fusion.Language/ISyntaxWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ namespace HotChocolate.Fusion.Language;
/// </summary>
internal interface ISyntaxWriter
{
/// <summary>
/// Gets the current column position in the output.
/// </summary>
int Column { get; }

/// <summary>
/// Increase writer indentation.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@ internal class StringSyntaxWriter(StringSyntaxWriterOptions? options = null) : I
?? new StringSyntaxWriterOptions();

private int _indent;
private int _column;
private readonly StringBuilder _stringBuilder = new();

/// <inheritdoc />
public int Column => _column;

public void Indent()
{
_indent++;
Expand All @@ -26,18 +30,40 @@ public void Unindent()
public void Write(char c)
{
_stringBuilder.Append(c);

if (c == '\n')
{
_column = 0;
}
else
{
_column++;
}
}

public void Write(string s)
{
_stringBuilder.Append(s);

var lastNewLine = s.LastIndexOf('\n');

if (lastNewLine >= 0)
{
_column = s.Length - lastNewLine - 1;
}
else
{
_column += s.Length;
}
}

public void WriteIndent(bool condition = true)
{
if (condition && _indent > 0)
{
_stringBuilder.Append(' ', _options.IndentSize * _indent);
var spaces = _options.IndentSize * _indent;
_stringBuilder.Append(' ', spaces);
_column += spaces;
}
}

Expand All @@ -46,6 +72,7 @@ public void WriteLine(bool condition = true)
if (condition)
{
_stringBuilder.Append(_options.NewLine);
_column = 0;
}
}

Expand All @@ -54,12 +81,14 @@ public void WriteSpace(bool condition = true)
if (condition)
{
_stringBuilder.Append(' ');
_column++;
}
}

public void Clear()
{
_stringBuilder.Clear();
_column = 0;
}

public override string ToString()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Transform_CompositeKey

## Apollo Federation SDL

```graphql
schema @link(url: "https://specs.apollo.dev/federation/v2.6", import: ["@key"]) {
query: Query
}
type Product @key(fields: "sku package") {
sku: String!
package: String!
name: String
}
type Query {
products: [Product]
_service: _Service!
_entities(representations: [_Any!]!): [_Entity]!
}
type _Service { sdl: String! }
union _Entity = Product
scalar FieldSet
scalar _Any
directive @key(fields: FieldSet! resolvable: Boolean = true) repeatable on OBJECT | INTERFACE
directive @link(url: String! import: [String!]) repeatable on SCHEMA
```

## Transformed SDL

```graphql
schema {
query: Query
}

type Query {
productBySkuAndPackage(package: String!, sku: String!): Product
@internal
@lookup
products: [Product]
}

type Product @key(fields: "sku package") {
name: String
package: String!
sku: String!
}
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Transform_ExternalDirective

## Apollo Federation SDL

```graphql
schema @link(url: "https://specs.apollo.dev/federation/v2.6", import: ["@key", "@external"]) {
query: Query
}
type Product @key(fields: "id") {
id: ID!
price: Float @external
}
type Query {
products: [Product]
_service: _Service!
_entities(representations: [_Any!]!): [_Entity]!
}
type _Service { sdl: String! }
union _Entity = Product
scalar FieldSet
scalar _Any
directive @key(fields: FieldSet! resolvable: Boolean = true) repeatable on OBJECT | INTERFACE
directive @external on FIELD_DEFINITION
directive @link(url: String! import: [String!]) repeatable on SCHEMA
```

## Transformed SDL

```graphql
schema {
query: Query
}

type Query {
productById(id: ID!): Product @internal @lookup
products: [Product]
}

type Product @key(fields: "id") {
id: ID!
}
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Transform_FullIntegration

## Apollo Federation SDL

```graphql
schema @link(url: "https://specs.apollo.dev/federation/v2.6", import: ["@key", "@requires", "@provides", "@external"]) {
query: Query
}
type Product @key(fields: "id") @key(fields: "sku package") {
id: ID!
sku: String!
package: String!
name: String
price: Float
weight: Float
inStock: Boolean
createdBy: User @provides(fields: "totalProductsCreated")
}
type User @key(fields: "id") {
id: ID!
username: String @external
totalProductsCreated: Int
}
type Review {
body: String
author: User
}
type Query {
product(id: ID!): Product
reviews: [Review]
_service: _Service!
_entities(representations: [_Any!]!): [_Entity]!
}
type _Service { sdl: String! }
union _Entity = Product | User
scalar FieldSet
scalar _Any
directive @key(fields: FieldSet! resolvable: Boolean = true) repeatable on OBJECT | INTERFACE
directive @requires(fields: FieldSet!) on FIELD_DEFINITION
directive @provides(fields: FieldSet!) on FIELD_DEFINITION
directive @external on FIELD_DEFINITION
directive @link(url: String! import: [String!]) repeatable on SCHEMA
```

## Transformed SDL

```graphql
schema {
query: Query
}

type Query {
product(id: ID!): Product
productById(id: ID!): Product @internal @lookup
productBySkuAndPackage(package: String!, sku: String!): Product
@internal
@lookup
reviews: [Review]
userById(id: ID!): User @internal @lookup
}

type Product @key(fields: "id") @key(fields: "sku package") {
createdBy: User @provides(fields: "totalProductsCreated")
id: ID!
inStock: Boolean
name: String
package: String!
price: Float
sku: String!
weight: Float
}

type Review {
author: User
body: String
}

type User @key(fields: "id") {
id: ID!
totalProductsCreated: Int
}
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Transform_KeyResolvableArgument

## Apollo Federation SDL

```graphql
schema @link(url: "https://specs.apollo.dev/federation/v2.6", import: ["@key"]) {
query: Query
}
type Product @key(fields: "id", resolvable: true) {
id: ID!
name: String
}
type Query {
products: [Product]
_service: _Service!
_entities(representations: [_Any!]!): [_Entity]!
}
type _Service { sdl: String! }
union _Entity = Product
scalar FieldSet
scalar _Any
directive @key(fields: FieldSet! resolvable: Boolean = true) repeatable on OBJECT | INTERFACE
directive @link(url: String! import: [String!]) repeatable on SCHEMA
```

## Transformed SDL

```graphql
schema {
query: Query
}

type Query {
productById(id: ID!): Product @internal @lookup
products: [Product]
}

type Product @key(fields: "id") {
id: ID!
name: String
}
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Transform_MultipleKeys

## Apollo Federation SDL

```graphql
schema @link(url: "https://specs.apollo.dev/federation/v2.6", import: ["@key"]) {
query: Query
}
type Product @key(fields: "id") @key(fields: "sku package") {
id: ID!
sku: String!
package: String!
name: String
}
type Query {
products: [Product]
_service: _Service!
_entities(representations: [_Any!]!): [_Entity]!
}
type _Service { sdl: String! }
union _Entity = Product
scalar FieldSet
scalar _Any
directive @key(fields: FieldSet! resolvable: Boolean = true) repeatable on OBJECT | INTERFACE
directive @link(url: String! import: [String!]) repeatable on SCHEMA
```

## Transformed SDL

```graphql
schema {
query: Query
}

type Query {
productById(id: ID!): Product @internal @lookup
productBySkuAndPackage(package: String!, sku: String!): Product
@internal
@lookup
products: [Product]
}

type Product @key(fields: "id") @key(fields: "sku package") {
id: ID!
name: String
package: String!
sku: String!
}
```
Loading
Loading