-
-
Notifications
You must be signed in to change notification settings - Fork 43
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 #375 from Code-Hex/fix/373
fix 373
- Loading branch information
Showing
10 changed files
with
683 additions
and
555 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
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,36 @@ | ||
import { ValidationSchemaPluginConfig } from './config'; | ||
import { TsVisitor } from '@graphql-codegen/typescript'; | ||
import { NameNode, GraphQLSchema } from 'graphql'; | ||
|
||
export class Visitor extends TsVisitor { | ||
constructor( | ||
private scalarDirection: 'input' | 'output' | 'both', | ||
private schema: GraphQLSchema, | ||
config: ValidationSchemaPluginConfig | ||
) { | ||
super(schema, config); | ||
} | ||
|
||
public getType(name: string) { | ||
return this.schema.getType(name); | ||
} | ||
|
||
public getNameNodeConverter(node: NameNode) { | ||
const typ = this.schema.getType(node.value); | ||
const astNode = typ?.astNode; | ||
if (astNode === undefined || astNode === null) { | ||
return undefined; | ||
} | ||
return { | ||
targetKind: astNode.kind, | ||
convertName: () => this.convertName(astNode.name.value), | ||
}; | ||
} | ||
|
||
public getScalarType(scalarName: string): string | null { | ||
if (this.scalarDirection === 'both') { | ||
return null; | ||
} | ||
return this.scalars[scalarName][this.scalarDirection]; | ||
} | ||
} |
Oops, something went wrong.