-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Work on using external modules #158
base: main
Are you sure you want to change the base?
Changes from 7 commits
a995481
69bba95
8a1fa3b
a431599
d9acd95
08a8573
da25562
f312118
58fedca
fda55a0
1b801c5
f889bfd
78cb2c2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
- [x] SDL should extend type for external types - I guess marking types in SDL | ||
- [x] can't generate graphql-js stuff, don't want to do it for externs - don't support graphql-js for this? | ||
- [x] all imported types (so support interfaces etc) | ||
- [x] Read SDL to actually do validation | ||
- [x] reenable global validations | ||
- [x] "modular" mode? like no full schema, but parts of schema but with full validation by resolving it? | ||
- [?] treat query/mutation/subscription as "import" type and extend it | ||
- [ ] all tests to add fixtures for metadata/resolver map | ||
- [ ] pluggable module resolution - too many variables there, use filepath by default, let users customize it | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In theory we only need this path in order to perform validation (is that right?). I wonder if there is a TypeScript API which will let us use the same (or most of) TypeScript's implementation of module resolution. I would need to avoid expecting the file to have a .js/.ts/.mjs/etc extension, but maybe something like that is exposed? I suspect that would be sufficient we could find something like that. I did see this: https://github.com/microsoft/TypeScript/blob/6a00bd2422ffa46c13ac8ff81d7b4b1157e60ba7/src/server/project.ts#L484 Which could be a good place to start looking. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure any non-ts files are included in how the typescript resolves it. There is also the whole story of "lib" in package.json and stuff like this. Ultimately there is no "well-known" spot for the GraphQL files, so it feels like it all might just break weirdly. I will experiment on this ofc, but I feel that there might not be an easy solution. |
||
- [ ] first try ts project resolution | ||
- [ ] how to handle overimporting? Improting whole SDL module "infects" the schema with types that might not be requested. | ||
- [ ] another check on error handling - I think eg enums and scalars accept stuff they shouldn't accept? |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,8 @@ import { | |
SPECIFIED_BY_TAG, | ||
CONTEXT_TAG, | ||
INFO_TAG, | ||
EXTERNAL_TAG, | ||
AllTags, | ||
} from "./Extractor"; | ||
|
||
export const ISSUE_URL = "https://github.com/captbaritone/grats/issues"; | ||
|
@@ -153,6 +155,10 @@ export function typeTagOnAliasOfNonObjectOrUnknown() { | |
return `Expected \`@${TYPE_TAG}\` type to be an object type literal (\`{ }\`) or \`unknown\`. For example: \`type Foo = { bar: string }\` or \`type Query = unknown\`.`; | ||
} | ||
|
||
export function nonExternalTypeAlias(tag: AllTags) { | ||
return `Expected \`@${tag}\` to be a type alias only if used with \`@${EXTERNAL_TAG}\``; | ||
captbaritone marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
// TODO: Add code action | ||
export function typeNameNotDeclaration() { | ||
return `Expected \`__typename\` to be a property declaration. For example: \`__typename: "MyType"\`.`; | ||
|
@@ -607,3 +613,17 @@ export function noTypesDefined() { | |
export function tsConfigNotFound(cwd: string) { | ||
return `Grats: Could not find \`tsconfig.json\` searching in ${cwd}.\n\nSee https://www.typescriptlang.org/download/ for instructors on how to add TypeScript to your project. Then run \`npx tsc --init\` to create a \`tsconfig.json\` file.`; | ||
} | ||
|
||
export function noModuleInGqlExternal() { | ||
return `Grats: @gqlExternal must include a module name in double quotes. For example: /** @gqlExternal "myModule" */`; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Diagnostics do not need to be prefixed with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You do have it in tsConfigNotFound, is that a mistake too? |
||
} | ||
|
||
export function externalNotInResolverMapMode() { | ||
return `Grats: @gqlExternal can only be used if grats is in EXPERIMENTAL__emitResolverMap mode. */`; | ||
freiksenet marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
export function externalOnWrongNode(extistingTags: string[]) { | ||
freiksenet marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return `Unexpected \`@${EXTERNAL_TAG}\` on type with following tags: ${extistingTags.join( | ||
", ", | ||
)}. \`@${EXTERNAL_TAG}\` can only be used on type declarations.`; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm onboard with this. Happy to have this as a separate PR if you want to merge that first.