-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'rc/salamander' into db/chore/pin-gql-request-version
- Loading branch information
Showing
39 changed files
with
432 additions
and
173 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@fuel-ts/providers": minor | ||
"@fuel-ts/errors": patch | ||
--- | ||
|
||
Implemented GraphQL subscriptions |
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
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 |
---|---|---|
@@ -1 +1 @@ | ||
18.14.1 | ||
18.18.2 |
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 |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
"author": "Fuel Labs <[email protected]> (https://fuel.network/)", | ||
"private": true, | ||
"engines": { | ||
"node": "^18.14.1", | ||
"node": "^18.18.2", | ||
"pnpm": "^8.9.0" | ||
}, | ||
"packageManager": "[email protected]", | ||
|
@@ -91,10 +91,5 @@ | |
"tsx": "^3.12.7", | ||
"turbo": "^1.8.8", | ||
"typescript": "~5.2.2" | ||
}, | ||
"pnpm": { | ||
"overrides": { | ||
"cross-fetch": "4.0.0" | ||
} | ||
} | ||
} |
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { FuelError } from '@fuel-ts/errors'; | ||
import type { DocumentNode } from 'graphql'; | ||
import { print } from 'graphql'; | ||
|
||
type FuelGraphQLSubscriberOptions = { | ||
url: string; | ||
query: DocumentNode; | ||
variables?: Record<string, unknown>; | ||
fetchFn: typeof fetch; | ||
abortController?: AbortController; | ||
}; | ||
|
||
class FuelSubscriptionStream implements TransformStream { | ||
readable: ReadableStream<FuelError | Record<string, unknown>>; | ||
writable: WritableStream<Uint8Array>; | ||
private readableStreamController!: ReadableStreamController<FuelError | Record<string, unknown>>; | ||
private static textDecoder = new TextDecoder(); | ||
|
||
constructor() { | ||
this.readable = new ReadableStream({ | ||
start: (controller) => { | ||
this.readableStreamController = controller; | ||
}, | ||
}); | ||
|
||
this.writable = new WritableStream<Uint8Array>({ | ||
write: (bytes) => { | ||
const text = FuelSubscriptionStream.textDecoder.decode(bytes); | ||
// the fuel node sends keep-alive messages that should be ignored | ||
if (text.startsWith('data:')) { | ||
const { data, errors } = JSON.parse(text.split('data:')[1]); | ||
if (Array.isArray(errors)) { | ||
this.readableStreamController.enqueue( | ||
new FuelError( | ||
FuelError.CODES.INVALID_REQUEST, | ||
errors.map((err) => err.message).join('\n\n') | ||
) | ||
); | ||
} else { | ||
this.readableStreamController.enqueue(data); | ||
} | ||
} | ||
}, | ||
}); | ||
} | ||
} | ||
|
||
export async function* fuelGraphQLSubscriber({ | ||
url, | ||
variables, | ||
query, | ||
fetchFn, | ||
}: FuelGraphQLSubscriberOptions) { | ||
const response = await fetchFn(`${url}-sub`, { | ||
method: 'POST', | ||
body: JSON.stringify({ | ||
query: print(query), | ||
variables, | ||
}), | ||
headers: { | ||
'Content-Type': 'application/json', | ||
Accept: 'text/event-stream', | ||
}, | ||
}); | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
const subscriptionStreamReader = response | ||
.body!.pipeThrough(new FuelSubscriptionStream()) | ||
.getReader(); | ||
|
||
while (true) { | ||
const { value, done } = await subscriptionStreamReader.read(); | ||
if (value instanceof FuelError) { | ||
throw value; | ||
} | ||
yield value; | ||
if (done) { | ||
break; | ||
} | ||
} | ||
} |
Oops, something went wrong.