-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from jensneuse/add-context-based-middleware
Add context based middleware
- Loading branch information
Showing
93 changed files
with
7,332 additions
and
4,891 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package hack | ||
|
||
// package hack contains not yet finished parts of the library | ||
// the contents should still be part of the main codebase to keep the discussion going | ||
// but we'll keep it separated from the main codebase |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package middleware | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/jensneuse/graphql-go-tools/pkg/middleware" | ||
"github.com/jensneuse/graphql-go-tools/pkg/testhelper" | ||
"testing" | ||
) | ||
|
||
func TestAssetMiddleware(t *testing.T) { | ||
|
||
run := func(schema, queryBefore, queryAfter string) { | ||
|
||
got := middleware.InvokeMiddleware(&AssetUrlMiddleware{}, context.Background(), schema, queryBefore) | ||
want := testhelper.UglifyRequestString(queryAfter) | ||
|
||
if want != got { | ||
panic(fmt.Errorf("want:\n%s\ngot:\n%s\n", want, got)) | ||
} | ||
} | ||
|
||
t.Run("asset handle transform", func(t *testing.T) { | ||
run(assetSchema, | ||
`query testQueryWithoutHandle { | ||
assets(first: 1) { | ||
id | ||
fileName | ||
url(transformation: {image: {resize: {width: 100, height: 100}}}) | ||
} | ||
}`, | ||
` query testQueryWithoutHandle { | ||
assets(first: 1) { | ||
id | ||
fileName | ||
handle | ||
} | ||
}`) | ||
}) | ||
t.Run("asset handle transform on empty selectionSet", func(t *testing.T) { | ||
run(assetSchema, | ||
`query testQueryWithoutHandle { | ||
assets(first: 1) { | ||
} | ||
}`, | ||
` query testQueryWithoutHandle { | ||
assets(first: 1) { | ||
handle | ||
} | ||
}`) | ||
}) | ||
|
||
} | ||
|
||
var assetSchema = ` | ||
schema { | ||
query: Query | ||
} | ||
type Query { | ||
assets(first: Int): [Asset] | ||
} | ||
type Asset implements Node @RequestMiddleware { | ||
status: Status! | ||
updatedAt: DateTime! | ||
createdAt: DateTime! | ||
id: ID! | ||
handle: String! | ||
fileName: String! | ||
height: Float | ||
width: Float | ||
size: Float | ||
mimeType: String | ||
url: String! | ||
}` |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.