-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9571cbe
commit aeb93c1
Showing
4 changed files
with
114 additions
and
0 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
src/tests/fixtures/resolver_context/ContextValueBeforeArgs.ts
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,10 @@ | ||
/** @gqlType */ | ||
export class SomeType { | ||
/** @gqlField */ | ||
greeting(ctx: SomeOtherType, args: { fallbackGreeting: string }): string { | ||
return ctx.greeting ?? args.fallbackGreeting; | ||
} | ||
} | ||
|
||
/** @gqlContext */ | ||
type SomeOtherType = { greeting?: string }; |
48 changes: 48 additions & 0 deletions
48
src/tests/fixtures/resolver_context/ContextValueBeforeArgs.ts.expected
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,48 @@ | ||
----------------- | ||
INPUT | ||
----------------- | ||
/** @gqlType */ | ||
export class SomeType { | ||
/** @gqlField */ | ||
greeting(ctx: SomeOtherType, args: { fallbackGreeting: string }): string { | ||
return ctx.greeting ?? args.fallbackGreeting; | ||
} | ||
} | ||
|
||
/** @gqlContext */ | ||
type SomeOtherType = { greeting?: string }; | ||
|
||
----------------- | ||
OUTPUT | ||
----------------- | ||
-- SDL -- | ||
type SomeType { | ||
greeting(fallbackGreeting: String!): String @metadata | ||
} | ||
-- TypeScript -- | ||
import { GraphQLSchema, GraphQLObjectType, GraphQLString, GraphQLNonNull } from "graphql"; | ||
export function getSchema(): GraphQLSchema { | ||
const SomeTypeType: GraphQLObjectType = new GraphQLObjectType({ | ||
name: "SomeType", | ||
fields() { | ||
return { | ||
greeting: { | ||
name: "greeting", | ||
type: GraphQLString, | ||
args: { | ||
fallbackGreeting: { | ||
name: "fallbackGreeting", | ||
type: new GraphQLNonNull(GraphQLString) | ||
} | ||
}, | ||
resolve(source, args, context) { | ||
return source.greeting(context, args); | ||
} | ||
} | ||
}; | ||
} | ||
}); | ||
return new GraphQLSchema({ | ||
types: [SomeTypeType] | ||
}); | ||
} |
12 changes: 12 additions & 0 deletions
12
src/tests/fixtures/resolver_context/ContextValueReadTwice.ts
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,12 @@ | ||
// No valid reason to do this, but just asserting that it works, since it happens to. | ||
|
||
/** @gqlType */ | ||
export class SomeType { | ||
/** @gqlField */ | ||
greeting(ctx: SomeOtherType, alsoContext: SomeOtherType): string { | ||
return ctx.greeting ?? "Hello, world!"; | ||
} | ||
} | ||
|
||
/** @gqlContext */ | ||
type SomeOtherType = { greeting?: string }; |
44 changes: 44 additions & 0 deletions
44
src/tests/fixtures/resolver_context/ContextValueReadTwice.ts.expected
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,44 @@ | ||
----------------- | ||
INPUT | ||
----------------- | ||
// No valid reason to do this, but just asserting that it works, since it happens to. | ||
|
||
/** @gqlType */ | ||
export class SomeType { | ||
/** @gqlField */ | ||
greeting(ctx: SomeOtherType, alsoContext: SomeOtherType): string { | ||
return ctx.greeting ?? "Hello, world!"; | ||
} | ||
} | ||
|
||
/** @gqlContext */ | ||
type SomeOtherType = { greeting?: string }; | ||
|
||
----------------- | ||
OUTPUT | ||
----------------- | ||
-- SDL -- | ||
type SomeType { | ||
greeting: String @metadata | ||
} | ||
-- TypeScript -- | ||
import { GraphQLSchema, GraphQLObjectType, GraphQLString } from "graphql"; | ||
export function getSchema(): GraphQLSchema { | ||
const SomeTypeType: GraphQLObjectType = new GraphQLObjectType({ | ||
name: "SomeType", | ||
fields() { | ||
return { | ||
greeting: { | ||
name: "greeting", | ||
type: GraphQLString, | ||
resolve(source, _args, context) { | ||
return source.greeting(context, context); | ||
} | ||
} | ||
}; | ||
} | ||
}); | ||
return new GraphQLSchema({ | ||
types: [SomeTypeType] | ||
}); | ||
} |