-
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.
Showing
20 changed files
with
388 additions
and
2 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
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
9 changes: 9 additions & 0 deletions
9
src/tests/fixtures/extend_type/fieldAsArrowFunctionLet.invalid.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,9 @@ | ||
/** @gqlType */ | ||
class SomeType { | ||
// No fields | ||
} | ||
|
||
/** @gqlField */ | ||
export let greeting = (_: SomeType): string => { | ||
return `Hello World`; | ||
}; |
24 changes: 24 additions & 0 deletions
24
src/tests/fixtures/extend_type/fieldAsArrowFunctionLet.invalid.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,24 @@ | ||
----------------- | ||
INPUT | ||
----------------- | ||
/** @gqlType */ | ||
class SomeType { | ||
// No fields | ||
} | ||
|
||
/** @gqlField */ | ||
export let greeting = (_: SomeType): string => { | ||
return `Hello World`; | ||
}; | ||
|
||
----------------- | ||
OUTPUT | ||
----------------- | ||
src/tests/fixtures/extend_type/fieldAsArrowFunctionLet.invalid.ts:7:8 - error: Expected `@gqlField` arrow function to be declared as `const`. | ||
|
||
7 export let greeting = (_: SomeType): string => { | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
8 return `Hello World`; | ||
~~~~~~~~~~~~~~~~~~~~~~~ | ||
9 }; | ||
~ |
9 changes: 9 additions & 0 deletions
9
src/tests/fixtures/extend_type/fieldAsArrowFunctionNotExported.invalid.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,9 @@ | ||
/** @gqlType */ | ||
class SomeType { | ||
// No fields | ||
} | ||
|
||
/** @gqlField */ | ||
const greeting = (_: SomeType): string => { | ||
return `Hello World`; | ||
}; |
32 changes: 32 additions & 0 deletions
32
src/tests/fixtures/extend_type/fieldAsArrowFunctionNotExported.invalid.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,32 @@ | ||
----------------- | ||
INPUT | ||
----------------- | ||
/** @gqlType */ | ||
class SomeType { | ||
// No fields | ||
} | ||
|
||
/** @gqlField */ | ||
const greeting = (_: SomeType): string => { | ||
return `Hello World`; | ||
}; | ||
|
||
----------------- | ||
OUTPUT | ||
----------------- | ||
-- Error Report -- | ||
src/tests/fixtures/extend_type/fieldAsArrowFunctionNotExported.invalid.ts:7:7 - error: Expected `@gqlField` to be an exported top-level declaration. Grats needs to import resolver functions into it's generated schema module, so the resolver function must be exported from the module. | ||
|
||
7 const greeting = (_: SomeType): string => { | ||
~~~~~~~~ | ||
|
||
|
||
-- Code Action: "Add export keyword to exported arrow function with @gqlField" (add-export-keyword-to-arrow-function) -- | ||
- Original | ||
+ Fixed | ||
|
||
@@ -6,3 +6,3 @@ | ||
/** @gqlField */ | ||
- const greeting = (_: SomeType): string => { | ||
+ export const greeting = (_: SomeType): string => { | ||
return `Hello World`; |
9 changes: 9 additions & 0 deletions
9
src/tests/fixtures/extend_type/fieldAsArrowFunctionVar.invalid.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,9 @@ | ||
/** @gqlType */ | ||
class SomeType { | ||
// No fields | ||
} | ||
|
||
/** @gqlField */ | ||
var greeting = (_: SomeType): string => { | ||
return `Hello World`; | ||
}; |
24 changes: 24 additions & 0 deletions
24
src/tests/fixtures/extend_type/fieldAsArrowFunctionVar.invalid.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,24 @@ | ||
----------------- | ||
INPUT | ||
----------------- | ||
/** @gqlType */ | ||
class SomeType { | ||
// No fields | ||
} | ||
|
||
/** @gqlField */ | ||
var greeting = (_: SomeType): string => { | ||
return `Hello World`; | ||
}; | ||
|
||
----------------- | ||
OUTPUT | ||
----------------- | ||
src/tests/fixtures/extend_type/fieldAsArrowFunctionVar.invalid.ts:7:1 - error: Expected `@gqlField` arrow function to be declared as `const`. | ||
|
||
7 var greeting = (_: SomeType): string => { | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
8 return `Hello World`; | ||
~~~~~~~~~~~~~~~~~~~~~~~ | ||
9 }; | ||
~ |
9 changes: 9 additions & 0 deletions
9
src/tests/fixtures/extend_type/fieldAsExportedArrowFunction.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,9 @@ | ||
/** @gqlType */ | ||
class SomeType { | ||
// No fields | ||
} | ||
|
||
/** @gqlField */ | ||
export const greeting = (_: SomeType): string => { | ||
return `Hello World`; | ||
}; |
42 changes: 42 additions & 0 deletions
42
src/tests/fixtures/extend_type/fieldAsExportedArrowFunction.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,42 @@ | ||
----------------- | ||
INPUT | ||
----------------- | ||
/** @gqlType */ | ||
class SomeType { | ||
// No fields | ||
} | ||
|
||
/** @gqlField */ | ||
export const greeting = (_: SomeType): string => { | ||
return `Hello World`; | ||
}; | ||
|
||
----------------- | ||
OUTPUT | ||
----------------- | ||
-- SDL -- | ||
type SomeType { | ||
greeting: String @metadata(exportName: "greeting", tsModulePath: "grats/src/tests/fixtures/extend_type/fieldAsExportedArrowFunction.ts") | ||
} | ||
-- TypeScript -- | ||
import { greeting as someTypeGreetingResolver } from "./fieldAsExportedArrowFunction"; | ||
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) { | ||
return someTypeGreetingResolver(source); | ||
} | ||
} | ||
}; | ||
} | ||
}); | ||
return new GraphQLSchema({ | ||
types: [SomeTypeType] | ||
}); | ||
} |
9 changes: 9 additions & 0 deletions
9
src/tests/fixtures/extend_type/fieldAsExportedAsyncArrowFunction.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,9 @@ | ||
/** @gqlType */ | ||
class SomeType { | ||
// No fields | ||
} | ||
|
||
/** @gqlField */ | ||
export const greeting = async (_: SomeType): Promise<string> => { | ||
return `Hello World`; | ||
}; |
42 changes: 42 additions & 0 deletions
42
src/tests/fixtures/extend_type/fieldAsExportedAsyncArrowFunction.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,42 @@ | ||
----------------- | ||
INPUT | ||
----------------- | ||
/** @gqlType */ | ||
class SomeType { | ||
// No fields | ||
} | ||
|
||
/** @gqlField */ | ||
export const greeting = async (_: SomeType): Promise<string> => { | ||
return `Hello World`; | ||
}; | ||
|
||
----------------- | ||
OUTPUT | ||
----------------- | ||
-- SDL -- | ||
type SomeType { | ||
greeting: String @metadata(exportName: "greeting", tsModulePath: "grats/src/tests/fixtures/extend_type/fieldAsExportedAsyncArrowFunction.ts") | ||
} | ||
-- TypeScript -- | ||
import { greeting as someTypeGreetingResolver } from "./fieldAsExportedAsyncArrowFunction"; | ||
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) { | ||
return someTypeGreetingResolver(source); | ||
} | ||
} | ||
}; | ||
} | ||
}); | ||
return new GraphQLSchema({ | ||
types: [SomeTypeType] | ||
}); | ||
} |
12 changes: 12 additions & 0 deletions
12
src/tests/fixtures/extend_type/fieldAsExportedMultipleVariables.invalid.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 @@ | ||
/** @gqlType */ | ||
class SomeType { | ||
// No fields | ||
} | ||
|
||
/** @gqlField */ | ||
export const greeting = (_: SomeType): string => { | ||
return `Hello World`; | ||
}, | ||
anotherGreeting = (_: SomeType): string => { | ||
return `Hello World`; | ||
}; |
30 changes: 30 additions & 0 deletions
30
src/tests/fixtures/extend_type/fieldAsExportedMultipleVariables.invalid.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,30 @@ | ||
----------------- | ||
INPUT | ||
----------------- | ||
/** @gqlType */ | ||
class SomeType { | ||
// No fields | ||
} | ||
|
||
/** @gqlField */ | ||
export const greeting = (_: SomeType): string => { | ||
return `Hello World`; | ||
}, | ||
anotherGreeting = (_: SomeType): string => { | ||
return `Hello World`; | ||
}; | ||
|
||
----------------- | ||
OUTPUT | ||
----------------- | ||
src/tests/fixtures/extend_type/fieldAsExportedMultipleVariables.invalid.ts:7:1 - error: Expected only one declaration when defining a `@gqlField`, found 2. | ||
|
||
7 export const greeting = (_: SomeType): string => { | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
8 return `Hello World`; | ||
~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
... | ||
11 return `Hello World`; | ||
~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
12 }; | ||
~~~~ |
7 changes: 7 additions & 0 deletions
7
src/tests/fixtures/extend_type/fieldAsExportedNothing.invalid.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,7 @@ | ||
/** @gqlType */ | ||
class SomeType { | ||
// No fields | ||
} | ||
|
||
/** @gqlField */ | ||
export const greeting; |
Oops, something went wrong.