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

ignore this testing things #2973

Open
wants to merge 9 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
3 changes: 2 additions & 1 deletion .codesandbox/ci.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"internals-js",
"query-graphs-js",
"query-planner-js",
"subgraph-js"
"subgraph-js",
"testing-wasm"
],
"sandboxes": [],
"node": "18"
Expand Down
3 changes: 2 additions & 1 deletion composition-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
},
"dependencies": {
"@apollo/federation-internals": "2.7.2",
"@apollo/query-graphs": "2.7.2"
"@apollo/query-graphs": "2.7.2",
"fake-composition-wasm": "0.1.0"
},
"peerDependencies": {
"graphql": "^16.5.0"
Expand Down
18 changes: 18 additions & 0 deletions composition-js/src/compose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ function validateCompositionOptions(options: CompositionOptions) {
}

export function compose(subgraphs: Subgraphs, options: CompositionOptions = {}): CompositionResult {
const { validate_graph_composition_wasm } = require('fake-composition-wasm');
// try {
// console.log(validate_graph_composition_wasm("type Query { hello: String }"));
// console.log(validate_graph_composition_wasm("type Query { hello: NotARealScalar }"));
// } catch (e) {
// console.log(e);
// }
validateCompositionOptions(options);

const upgradeResult = upgradeSubgraphsIfNecessary(subgraphs);
Expand All @@ -55,6 +62,11 @@ export function compose(subgraphs: Subgraphs, options: CompositionOptions = {}):

const toMerge = upgradeResult.subgraphs;
const validationErrors = toMerge.validate();

// toMerge.values().forEach(subgraph => {
// const sdl = printSchema(subgraph.schema);
// console.log(validate_graph_composition_wasm(sdl));
// });
if (validationErrors) {
return { errors: validationErrors };
}
Expand Down Expand Up @@ -86,6 +98,12 @@ export function compose(subgraphs: Subgraphs, options: CompositionOptions = {}):
return { errors: [err] };
}

try {
console.log(validate_graph_composition_wasm(supergraphSdl));
} catch(err) {
return { errors: [err] };
}

return {
schema: supergraph.schema,
supergraphSdl,
Expand Down
3 changes: 2 additions & 1 deletion composition-js/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"exclude": ["**/__tests__"],
"references": [
{ "path": "../internals-js" },
{ "path": "../query-graphs-js" }
{ "path": "../query-graphs-js" },
{ "path": "../testing-wasm" }
]
}
14 changes: 12 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
"query-planner-js",
"query-graphs-js",
"subgraph-js",
"federation-integration-testsuite-js"
"federation-integration-testsuite-js",
"testing-wasm"
],
"devDependencies": {
"@apollo/cache-control-types": "1.0.3",
Expand Down
7 changes: 7 additions & 0 deletions testing-wasm/fake_composition_wasm.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* tslint:disable */
/* eslint-disable */
/**
* @param {string} sdl
* @returns {any}
*/
export function validate_graph_composition_wasm(sdl: string): any;
155 changes: 155 additions & 0 deletions testing-wasm/fake_composition_wasm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
let imports = {};
imports['__wbindgen_placeholder__'] = module.exports;
let wasm;
const { TextDecoder, TextEncoder } = require(`util`);

let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });

cachedTextDecoder.decode();

let cachedUint8Memory0 = null;

function getUint8Memory0() {
if (cachedUint8Memory0 === null || cachedUint8Memory0.byteLength === 0) {
cachedUint8Memory0 = new Uint8Array(wasm.memory.buffer);
}
return cachedUint8Memory0;
}

function getStringFromWasm0(ptr, len) {
ptr = ptr >>> 0;
return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len));
}

const heap = new Array(128).fill(undefined);

heap.push(undefined, null, true, false);

let heap_next = heap.length;

function addHeapObject(obj) {
if (heap_next === heap.length) heap.push(heap.length + 1);
const idx = heap_next;
heap_next = heap[idx];

heap[idx] = obj;
return idx;
}

let WASM_VECTOR_LEN = 0;

let cachedTextEncoder = new TextEncoder('utf-8');

const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
? function (arg, view) {
return cachedTextEncoder.encodeInto(arg, view);
}
: function (arg, view) {
const buf = cachedTextEncoder.encode(arg);
view.set(buf);
return {
read: arg.length,
written: buf.length
};
});

function passStringToWasm0(arg, malloc, realloc) {

if (realloc === undefined) {
const buf = cachedTextEncoder.encode(arg);
const ptr = malloc(buf.length, 1) >>> 0;
getUint8Memory0().subarray(ptr, ptr + buf.length).set(buf);
WASM_VECTOR_LEN = buf.length;
return ptr;
}

let len = arg.length;
let ptr = malloc(len, 1) >>> 0;

const mem = getUint8Memory0();

let offset = 0;

for (; offset < len; offset++) {
const code = arg.charCodeAt(offset);
if (code > 0x7F) break;
mem[ptr + offset] = code;
}

if (offset !== len) {
if (offset !== 0) {
arg = arg.slice(offset);
}
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
const view = getUint8Memory0().subarray(ptr + offset, ptr + len);
const ret = encodeString(arg, view);

offset += ret.written;
ptr = realloc(ptr, len, offset, 1) >>> 0;
}

WASM_VECTOR_LEN = offset;
return ptr;
}

let cachedInt32Memory0 = null;

function getInt32Memory0() {
if (cachedInt32Memory0 === null || cachedInt32Memory0.byteLength === 0) {
cachedInt32Memory0 = new Int32Array(wasm.memory.buffer);
}
return cachedInt32Memory0;
}

function getObject(idx) { return heap[idx]; }

function dropObject(idx) {
if (idx < 132) return;
heap[idx] = heap_next;
heap_next = idx;
}

function takeObject(idx) {
const ret = getObject(idx);
dropObject(idx);
return ret;
}
/**
* @param {string} sdl
* @returns {any}
*/
module.exports.validate_graph_composition_wasm = function(sdl) {
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
const ptr0 = passStringToWasm0(sdl, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
const len0 = WASM_VECTOR_LEN;
wasm.validate_graph_composition_wasm(retptr, ptr0, len0);
var r0 = getInt32Memory0()[retptr / 4 + 0];
var r1 = getInt32Memory0()[retptr / 4 + 1];
var r2 = getInt32Memory0()[retptr / 4 + 2];
if (r2) {
throw takeObject(r1);
}
return takeObject(r0);
} finally {
wasm.__wbindgen_add_to_stack_pointer(16);
}
};

module.exports.__wbg_log_9176428602472795 = function(arg0, arg1) {
console.log(getStringFromWasm0(arg0, arg1));
};

module.exports.__wbindgen_string_new = function(arg0, arg1) {
const ret = getStringFromWasm0(arg0, arg1);
return addHeapObject(ret);
};

const path = require('path').join(__dirname, 'fake_composition_wasm_bg.wasm');
const bytes = require('fs').readFileSync(path);

const wasmModule = new WebAssembly.Module(bytes);
const wasmInstance = new WebAssembly.Instance(wasmModule, imports);
wasm = wasmInstance.exports;
module.exports.__wasm = wasm;

Binary file added testing-wasm/fake_composition_wasm_bg.wasm
Binary file not shown.
7 changes: 7 additions & 0 deletions testing-wasm/fake_composition_wasm_bg.wasm.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* tslint:disable */
/* eslint-disable */
export const memory: WebAssembly.Memory;
export function validate_graph_composition_wasm(a: number, b: number, c: number): void;
export function __wbindgen_add_to_stack_pointer(a: number): number;
export function __wbindgen_malloc(a: number, b: number): number;
export function __wbindgen_realloc(a: number, b: number, c: number, d: number): number;
14 changes: 14 additions & 0 deletions testing-wasm/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "fake-composition-wasm",
"collaborators": [
"Lenny Burdette <[email protected]>"
],
"version": "0.1.0",
"files": [
"fake_composition_wasm_bg.wasm",
"fake_composition_wasm.js",
"fake_composition_wasm.d.ts"
],
"main": "fake_composition_wasm.js",
"types": "fake_composition_wasm.d.ts"
}
3 changes: 3 additions & 0 deletions testing-wasm/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../tsconfig.base",
}
2 changes: 1 addition & 1 deletion tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"noUnusedLocals": true,
"useUnknownInCatchVariables": false,
"forceConsistentCasingInFileNames": true,
"lib": ["es2019", "esnext.asynciterable"],
"lib": ["esnext", "dom"],
"types": ["node"],
"baseUrl": ".",
"paths": {
Expand Down
1 change: 1 addition & 0 deletions tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
{ "path": "./gateway-js" },
{ "path": "./federation-integration-testsuite-js" },
{ "path": "./subgraph-js" },
{ "path": "./testing-wasm" },
]
}