mirror of
https://github.com/captbaritone/webamp.git
synced 2026-07-24 02:27:37 +00:00
Start to introduce Node
This commit is contained in:
parent
a028a65732
commit
df5aa4f5db
6 changed files with 37 additions and 12 deletions
|
|
@ -20,7 +20,7 @@ Object {
|
|||
"average_color": null,
|
||||
"download_url": "https://cdn.webampskins.org/skins/a_fake_md5.wsz",
|
||||
"filename": "path.wsz",
|
||||
"id": 50,
|
||||
"id": "U2tpbl9fYV9mYWtlX21kNQ==",
|
||||
"internet_archive_item": Object {
|
||||
"identifier": "a_fake_ia_identifier",
|
||||
"metadata_url": "https://archive.org/metadata/a_fake_ia_identifier",
|
||||
|
|
|
|||
|
|
@ -44,23 +44,46 @@ async function graphQLRequest(query: string, variables?: any) {
|
|||
.post("/graphql")
|
||||
.send({ query, variables: variables ?? {} });
|
||||
if (body.errors && body.errors.length) {
|
||||
console.warn(body);
|
||||
for (const err of body.errors) {
|
||||
console.warn(err.message);
|
||||
console.warn('Stack', err.stack)
|
||||
}
|
||||
}
|
||||
|
||||
return body;
|
||||
}
|
||||
|
||||
test.skip(".node", async () => {
|
||||
test(".node", async () => {
|
||||
const { data } = await graphQLRequest(gql`
|
||||
query {
|
||||
skins(limit: 1) {
|
||||
node {
|
||||
skins(first: 1) {
|
||||
nodes {
|
||||
id
|
||||
md5
|
||||
}
|
||||
}
|
||||
}
|
||||
`);
|
||||
expect(data).toEqual({ skins: [{ node: { id: "hwllo" } }] });
|
||||
const skin = data.skins.nodes[0];
|
||||
expect(skin.id).toEqual("U2tpbl9fYV9mYWtlX21kNQ==");
|
||||
|
||||
const { data: data2 } = await graphQLRequest(gql`
|
||||
query MyQuery($id: ID!) {
|
||||
node(id: $id) {
|
||||
... on Skin {
|
||||
md5
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
`, { id: skin.id });
|
||||
expect(
|
||||
|
||||
|
||||
|
||||
data2.node).toEqual({ md5: skin.md5 })
|
||||
});
|
||||
|
||||
describe(".me", () => {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
export interface NodeResolver {
|
||||
id({ id }): Promise<string>
|
||||
__typename: String
|
||||
};
|
||||
|
||||
export function toId(graphqlType: string, id: string) {
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ class RootResolver extends MutationResolver {
|
|||
// TODO Use typeResolver
|
||||
switch (graphqlType) {
|
||||
case "Skin": {
|
||||
const skin = await SkinModel.fromMd5(ctx, id);
|
||||
const skin = await SkinModel.fromMd5(ctx, localId);
|
||||
if (skin == null) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ export default class SkinResolver implements NodeResolver {
|
|||
constructor(model: SkinModel) {
|
||||
this._model = model;
|
||||
}
|
||||
__typename = "Skin";
|
||||
async id() {
|
||||
return toId("Skin", this.md5())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
"""
|
||||
A globally unique object. The `id` here is intended only for use within
|
||||
A globally unique object. The `id` here is intended only for use within
|
||||
GraphQL.
|
||||
https://graphql.org/learn/global-object-identification/
|
||||
"""
|
||||
|
|
@ -12,9 +12,9 @@ A classic Winamp skin
|
|||
"""
|
||||
type Skin implements Node {
|
||||
"""
|
||||
Database ID of the skin
|
||||
GraphQL ID of the skin
|
||||
"""
|
||||
id: Int
|
||||
id: ID!
|
||||
|
||||
"""
|
||||
MD5 hash of the skin's file
|
||||
|
|
@ -327,7 +327,7 @@ enum SkinUploadStatus {
|
|||
the skin will be retried at a later time.
|
||||
"""
|
||||
ERRORED
|
||||
|
||||
|
||||
"""
|
||||
An error occured processing the skin, but it was the fault of the server. It
|
||||
will be processed at a later date.
|
||||
|
|
@ -514,7 +514,7 @@ type Query {
|
|||
https://graphql.org/learn/global-object-identification/
|
||||
"""
|
||||
node(id: ID): Node
|
||||
|
||||
|
||||
"""
|
||||
The currently authenticated user, if any.
|
||||
"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue