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
1d1c41c
commit 957a70f
Showing
6 changed files
with
100 additions
and
17 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
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
17 changes: 17 additions & 0 deletions
17
website/docs/04-docblock-tags/snippets/02-static-method-extending-query.grats.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,17 @@ | ||
/** @gqlType */ | ||
type Query = unknown; | ||
|
||
/** @gqlType */ | ||
export class User { | ||
constructor( | ||
/** @gqlField */ | ||
public name: string, | ||
) {} | ||
|
||
// highlight-start | ||
/** @gqlField */ | ||
static getUser(_: Query): User { | ||
return new User("Elizabeth"); | ||
} | ||
// highlight-end | ||
} |
60 changes: 60 additions & 0 deletions
60
website/docs/04-docblock-tags/snippets/02-static-method-extending-query.out
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,60 @@ | ||
/** @gqlType */ | ||
type Query = unknown; | ||
|
||
/** @gqlType */ | ||
export class User { | ||
constructor( | ||
/** @gqlField */ | ||
public name: string, | ||
) {} | ||
|
||
// highlight-start | ||
/** @gqlField */ | ||
static getUser(_: Query): User { | ||
return new User("Elizabeth"); | ||
} | ||
// highlight-end | ||
} | ||
|
||
=== SNIP === | ||
type Query { | ||
getUser: User | ||
} | ||
|
||
type User { | ||
name: String | ||
} | ||
=== SNIP === | ||
import { User as queryGetUserResolver } from "./02-static-method-extending-query.grats"; | ||
import { GraphQLSchema, GraphQLObjectType, GraphQLString } from "graphql"; | ||
export function getSchema(): GraphQLSchema { | ||
const UserType: GraphQLObjectType = new GraphQLObjectType({ | ||
name: "User", | ||
fields() { | ||
return { | ||
name: { | ||
name: "name", | ||
type: GraphQLString | ||
} | ||
}; | ||
} | ||
}); | ||
const QueryType: GraphQLObjectType = new GraphQLObjectType({ | ||
name: "Query", | ||
fields() { | ||
return { | ||
getUser: { | ||
name: "getUser", | ||
type: UserType, | ||
resolve(source) { | ||
return queryGetUserResolver.getUser(source); | ||
} | ||
} | ||
}; | ||
} | ||
}); | ||
return new GraphQLSchema({ | ||
query: QueryType, | ||
types: [QueryType, UserType] | ||
}); | ||
} |