chore
This commit is contained in:
@@ -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));
|
||||
// })();
|
||||
|
||||
Reference in New Issue
Block a user