Skip to content

Commit

Permalink
fix: inputType for getTypeInfo and offsets
Browse files Browse the repository at this point in the history
  • Loading branch information
acao committed Sep 9, 2024
1 parent b16997a commit d19672e
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ describe('MessageProcessor with config', () => {
character: 0,
},
end: {
line: 102 + offset,
line: 103 + offset,
character: 1,
},
});
Expand All @@ -450,11 +450,11 @@ describe('MessageProcessor with config', () => {
// this might break, please adjust if you see a failure here
expect(serializeRange(schemaDefs[0].range)).toEqual({
start: {
line: 104 + offset,
line: 105 + offset,
character: 0,
},
end: {
line: 112 + offset,
line: 113 + offset,
character: 1,
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -704,14 +704,14 @@ describe('getAutocompleteSuggestions', () => {

// TODO: decide if we want this. Discussing with @benjie, we might want to actually give the user flexibility here,
// instead of being strict
// it('provides no more field suggestions once a oneOf field is chose and a user begins typing another field', () => {
// expect(
// testSuggestions(
// '{ oneOfInputTypeTest(oneOf: { value: 2 d',
// new Position(0, 40),
// ),
// ).toEqual([]);
// });
it('provides no more field suggestions once a oneOf field is chose and a user begins typing another field', () => {
expect(
testSuggestions(
'{ oneOfInputTypeTest(oneOf: { value: 2 d',
new Position(0, 40),
),
).toEqual([]);
});

it('provides correct field name suggestion inside inline fragment', () => {
expect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,8 @@ export function getAutocompleteSuggestions(
// @oneOf logic!
console.log(state.prevState?.prevState?.kind, !!typeInfo.inputType);

Check failure on line 316 in packages/graphql-language-service/src/interface/getAutocompleteSuggestions.ts

View workflow job for this annotation

GitHub Actions / ESLint

Unexpected console statement

Check failure on line 316 in packages/graphql-language-service/src/interface/getAutocompleteSuggestions.ts

View workflow job for this annotation

GitHub Actions / ESLint

Use destructured variables over properties

Check failure on line 316 in packages/graphql-language-service/src/interface/getAutocompleteSuggestions.ts

View workflow job for this annotation

GitHub Actions / ESLint

Unexpected implicit coercion encountered. Use `Boolean(typeInfo.inputType)` instead
if (
typeInfo?.inputType &&
'isOneOf' in typeInfo.inputType &&
typeInfo?.inputType?.isOneOf === true &&
(state.prevState?.prevState?.kind !== 'Argument' || token.string !== '{')

Check failure on line 321 in packages/graphql-language-service/src/interface/getAutocompleteSuggestions.ts

View workflow job for this annotation

GitHub Actions / ESLint

Use destructured variables over properties
) {
Expand Down
5 changes: 3 additions & 2 deletions packages/graphql-language-service/src/parser/getTypeInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,13 +245,14 @@ export function getTypeInfo(
? objectType.getFields()
: null;
inputType = objectType;
console.log(inputType);
break;
// TODO: needs tests
case RuleKinds.OBJECT_FIELD:
const objectField =
state.name && objectFieldDefs ? objectFieldDefs[state.name] : null;
inputType = objectField?.type;
if (objectField?.type) {
inputType = objectField?.type;
}
// @ts-expect-error
fieldDef = objectField as GraphQLField<null, null>;
type = fieldDef ? fieldDef.type : null;
Expand Down
2 changes: 0 additions & 2 deletions packages/graphql-language-service/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ import type {
GraphQLObjectType,
GraphQLType,
GraphQLDirective,
GraphQLInputType,
GraphQLInputObjectType,
} from 'graphql';

export type Maybe<T> = T | null | undefined;
Expand Down

0 comments on commit d19672e

Please sign in to comment.