This commit is contained in:
tornado
2025-02-18 11:31:29 +08:00
parent b61af75169
commit 9ff78b25ce
10 changed files with 6892 additions and 52 deletions

View File

@@ -1,32 +1,39 @@
import { ofetch } from 'ofetch';
// import { gql } from './__generated__';
import { ApolloClient, InMemoryCache, gql } from '@apollo/client';
const gqlText = `
query QueryAllUserProjects {
demo_users{
id
name
projects{
id
demo_projects_id{
const gqlText = gql(
`
query get {
demo_projects {
id
name
}
}
}
}
`;
}`
);
const client = new ApolloClient({
uri: process.env.GRAPHQL_ENDPOINT_WITH_TOKEN, // 你的 GraphQL 服务器地址
cache: new InMemoryCache(), // 内置的内存缓存
// 可以添加更多选项,比如 headers、fetchPolicy 等
});
(async () => {
const result = await ofetch("http://172.16.6.246:8055/graphql", {
method: 'POST',
headers: {
'Authorization': 'Bearer WkVWFMiFcrjsXRZqsL30Cd4Sboe0DRk-',
'Content-Type': 'application/json',
},
body: {
query: gqlText,
variables: {}
},
const result = await client.query({
query: gqlText
})
console.log(JSON.stringify(result, null, 2));
})();
})
// (async () => {
// const result = await ofetch("http://172.16.6.246:8055/graphql", {
// method: 'POST',
// headers: {
// 'Authorization': 'Bearer WkVWFMiFcrjsXRZqsL30Cd4Sboe0DRk-',
// 'Content-Type': 'application/json',
// },
// body: {
// query: gqlText,
// variables: {}
// },
// })
// console.log(JSON.stringify(result, null, 2));
// })();