Comparing version 0.0.6 to 0.0.7
@@ -14,2 +14,3 @@ /// <reference types="@cloudflare/workers-types" /> | ||
register(schema: string, resolve: GraphQLFieldResolver<any, any, any, any>): void; | ||
register(schema: string, resolves: Record<string, GraphQLFieldResolver<any, any, any, any>>): void; | ||
} |
@@ -136,2 +136,20 @@ import { mergeSchemas } from '@graphql-tools/schema'; | ||
} | ||
else if (args.length === 2 && typeof args[0] === 'string' && typeof args[1] === 'object') { | ||
const s = buildSchema(args[0]); | ||
const typs = ['Query', 'Mutuation', 'Subscription']; | ||
for (const t of typs) { | ||
const obj = s.getTypeMap()[t]; | ||
if (obj instanceof GraphQLObjectType) { | ||
for (const f of Object.keys(obj.getFields())) { | ||
if (args[1][f]) { | ||
obj.getFields()[f].resolve = args[1][f]; | ||
} | ||
else { | ||
throw new Error(`no resolve function for ${obj.getFields()[f]}`); | ||
} | ||
} | ||
} | ||
} | ||
this.schemas.push(s); | ||
} | ||
else { | ||
@@ -138,0 +156,0 @@ throw new Error('invalid of parameters for register'); |
@@ -117,2 +117,77 @@ import { GraphQLObjectType, GraphQLString, GraphQLSchema } from 'graphql'; | ||
}); | ||
it('should work when schema string mulitiple query registered', async () => { | ||
const app = new EdgeQL(); | ||
app.register(` | ||
type Query { | ||
hi: String | ||
hello: String | ||
ping: String | ||
} | ||
`, { | ||
hello: () => 'world', | ||
hi: () => 'world', | ||
ping: () => 'pong', | ||
}); | ||
let req = new Request('http://localhost', { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify({ | ||
query: 'query H { hello }', | ||
variables: {}, | ||
operationName: 'H', | ||
extensions: {}, | ||
}), | ||
}); | ||
let res = await app.fetch(req); | ||
expect(res.status).toBe(200); | ||
expect(await res.json()).toEqual({ | ||
data: { | ||
hello: 'world', | ||
}, | ||
}); | ||
req = new Request('http://localhost', { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify({ | ||
query: 'query H { hi }', | ||
variables: {}, | ||
operationName: 'H', | ||
extensions: {}, | ||
}), | ||
}); | ||
res = await app.fetch(req); | ||
expect(res.status).toBe(200); | ||
expect(await res.json()).toEqual({ | ||
data: { | ||
hi: 'world', | ||
}, | ||
}); | ||
req = new Request('http://localhost', { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify({ | ||
query: `query H { | ||
hi | ||
ping | ||
}`, | ||
variables: {}, | ||
operationName: 'H', | ||
extensions: {}, | ||
}), | ||
}); | ||
res = await app.fetch(req); | ||
expect(res.status).toBe(200); | ||
expect(await res.json()).toEqual({ | ||
data: { | ||
hi: 'world', | ||
ping: 'pong', | ||
}, | ||
}); | ||
}); | ||
}); |
{ | ||
"name": "edgeql", | ||
"version": "0.0.6", | ||
"version": "0.0.7", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
33078
954