Skip to content
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

Adds a way to get the perspective by using a shared URL #29

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/Ad4mClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,14 @@ describe('Ad4mClient', () => {
expect(p.name).toBe('test-perspective-1')
})

it('fromUrl() smoke test', async () => {
const p1 = await ad4mClient.perspective.fromUrl('neighbourhood://Qm12345')
expect(p1.sharedUrl).toBe('neighbourhood://Qm12345')
expect(p1.name).toBe('test-perspective-2')
const p2 = await ad4mClient.perspective.fromUrl('neighbourhood://Qm67891')
expect(p2).toBeNull()
})

it('snapshotByUUID() smoke test', async () => {
const ps = await ad4mClient.perspective.snapshotByUUID('00004')
expect(ps.links.length).toBe(1)
Expand Down
13 changes: 13 additions & 0 deletions src/perspectives/PerspectiveClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,19 @@ export default class PerspectiveClient {
return new PerspectiveProxy(perspective, this)
}

async fromUrl(url: string): Promise<PerspectiveProxy|null> {
const { fromUrl } = unwrapApolloResult(await this.#apolloClient.query({
query: gql`query fromUrl($url: String!) {
fromUrl(url: $url) {
${PERSPECTIVE_HANDLE_FIELDS}
}
}`,
variables: { url }
}))
if(!fromUrl) return null
return new PerspectiveProxy(fromUrl, this)
}

async snapshotByUUID(uuid: string): Promise<Perspective|null> {
const { perspectiveSnapshot } = unwrapApolloResult(await this.#apolloClient.query({
query: gql`query perspectiveSnapshot($uuid: String!) {
Expand Down
11 changes: 11 additions & 0 deletions src/perspectives/PerspectiveResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,17 @@ export default class PerspectiveResolver {
return new PerspectiveHandle(uuid, 'test-perspective-1')
}

@Query(returns => PerspectiveHandle, {nullable: true})
fromUrl(@Arg('url') url: string): PerspectiveHandle|null {
if (url === 'neighbourhood://Qm12345') {
const perspective = new PerspectiveHandle(url, 'test-perspective-2');
perspective.sharedUrl = "neighbourhood://Qm12345";
return perspective;
}

return null;
}

@Query(returns => Perspective, {nullable: true})
perspectiveSnapshot(@Arg('uuid') uuid: string): Perspective|null {
return new Perspective([testLink])
Expand Down