-
Notifications
You must be signed in to change notification settings - Fork 0
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 #7 from rintoj/feat/reference-provider
Feat/reference provider
- Loading branch information
Showing
15 changed files
with
633 additions
and
125 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
98 changes: 98 additions & 0 deletions
98
src/definition-provider/definition-provider-from-schema.test.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,98 @@ | ||
import { Position, Range } from '../diff' | ||
import { trimSpaces } from '../util/trim-spaces' | ||
import { provideDefinitionFromSchema } from './definition-provider-from-schema' | ||
|
||
const schema = ` | ||
type User { | ||
id: ID! | ||
name: String | ||
address: Address | ||
status: UserStatus | ||
} | ||
enum UserStatus { | ||
ACTIVE, | ||
DELETED | ||
} | ||
type Address { | ||
id: String | ||
address: String | ||
city: City | ||
} | ||
type City { | ||
name: String | ||
code: String | ||
} | ||
""" | ||
Tweet object | ||
used as primitive type | ||
""" | ||
type Tweet { | ||
tweetId: ID! | ||
mentions: [User!] | ||
} | ||
type Query { | ||
me: User | ||
user(id: ID!): User | ||
tweet(id: ID!): Tweet | ||
} | ||
type Mutation { | ||
createUser(name: String): User | ||
updateUser(id: ID!, name: String): User | ||
} | ||
type Subscription { | ||
onUserChange(id: ID!): User | ||
} | ||
` | ||
|
||
function getAt(schema: string, range: Range | null) { | ||
if (!range) return | ||
const lines = schema.split('\n').slice(range.start.line, range.end.line + 1) | ||
return lines.join('\n') | ||
} | ||
|
||
describe('provideDefinitionFromSchema', () => { | ||
test('should provide return address type', async () => { | ||
const range = provideDefinitionFromSchema(schema, new Position(4, 16)) | ||
const output = getAt(schema, range) | ||
expect(output).toEqual( | ||
trimSpaces(` | ||
type Address { | ||
id: String | ||
address: String | ||
city: City | ||
}`), | ||
) | ||
}) | ||
|
||
test('should provide user status', async () => { | ||
const range = provideDefinitionFromSchema(schema, new Position(5, 16)) | ||
const output = getAt(schema, range) | ||
expect(output).toEqual( | ||
trimSpaces(` | ||
enum UserStatus { | ||
ACTIVE, | ||
DELETED | ||
}`), | ||
) | ||
}) | ||
|
||
test('should provide tweet type', async () => { | ||
const range = provideDefinitionFromSchema(schema, new Position(36, 22)) | ||
const output = getAt(schema, range) | ||
expect(output).toEqual( | ||
trimSpaces(` | ||
type Tweet { | ||
tweetId: ID! | ||
mentions: [User!] | ||
}`), | ||
) | ||
}) | ||
}) |
Oops, something went wrong.