diff --git a/src/Ad4mClient.test.ts b/src/Ad4mClient.test.ts index fc5815c..7a3429b 100644 --- a/src/Ad4mClient.test.ts +++ b/src/Ad4mClient.test.ts @@ -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) diff --git a/src/perspectives/PerspectiveClient.ts b/src/perspectives/PerspectiveClient.ts index 88b079e..ac8434a 100644 --- a/src/perspectives/PerspectiveClient.ts +++ b/src/perspectives/PerspectiveClient.ts @@ -111,6 +111,19 @@ export default class PerspectiveClient { return new PerspectiveProxy(perspective, this) } + async fromUrl(url: string): Promise { + 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 { const { perspectiveSnapshot } = unwrapApolloResult(await this.#apolloClient.query({ query: gql`query perspectiveSnapshot($uuid: String!) { diff --git a/src/perspectives/PerspectiveResolver.ts b/src/perspectives/PerspectiveResolver.ts index 742d8c3..63b6799 100644 --- a/src/perspectives/PerspectiveResolver.ts +++ b/src/perspectives/PerspectiveResolver.ts @@ -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])