kandi background
Explore Kits

apollo | reliable configuration management system suitable | Microservice library

 by   ctripcorp Java Version: v1.9.0 License: Apache-2.0

 by   ctripcorp Java Version: v1.9.0 License: Apache-2.0

Download this library from

kandi X-RAY | apollo Summary

apollo is a Java library typically used in Architecture, Microservice, Spring Boot, Spring, Docker applications. apollo has no bugs, it has no vulnerabilities, it has build file available, it has a Permissive License and it has high support. You can download it from GitHub, Maven.
Apollo is a reliable configuration management system. It can centrally manage the configurations of different applications and different clusters. It is suitable for microservice configuration management scenarios. The server side is developed based on Spring Boot and Spring Cloud, which can simply run without the need to install additional application containers such as Tomcat. The Java SDK does not rely on any framework and can run in all Java runtime environments. It also has good support for Spring/Spring Boot environments. The .Net SDK does not rely on any framework and can run in all .Net runtime environments. For more details of the product introduction, please refer Introduction to Apollo Configuration Center. For local demo purpose, please refer Quick Start.
Support
Support
Quality
Quality
Security
Security
License
License
Reuse
Reuse

kandi-support Support

  • apollo has a highly active ecosystem.
  • It has 25294 star(s) with 9279 fork(s). There are 1307 watchers for this library.
  • It had no major release in the last 12 months.
  • There are 144 open issues and 2410 have been closed. On average issues are closed in 97 days. There are 14 open pull requests and 0 closed requests.
  • It has a positive sentiment in the developer community.
  • The latest version of apollo is v1.9.0
apollo Support
Best in #Microservice
Average in #Microservice
apollo Support
Best in #Microservice
Average in #Microservice

quality kandi Quality

  • apollo has 0 bugs and 0 code smells.
apollo Quality
Best in #Microservice
Average in #Microservice
apollo Quality
Best in #Microservice
Average in #Microservice

securitySecurity

  • apollo has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
  • apollo code analysis shows 0 unresolved vulnerabilities.
  • There are 0 security hotspots that need review.
apollo Security
Best in #Microservice
Average in #Microservice
apollo Security
Best in #Microservice
Average in #Microservice

license License

  • apollo is licensed under the Apache-2.0 License. This license is Permissive.
  • Permissive licenses have the least restrictions, and you can use them in most projects.
apollo License
Best in #Microservice
Average in #Microservice
apollo License
Best in #Microservice
Average in #Microservice

buildReuse

  • apollo releases are available to install and integrate.
  • Deployable package is available in Maven.
  • Build file is available. You can build the component from source.
  • apollo saves you 52494 person hours of effort in developing the same functionality from scratch.
  • It has 65974 lines of code, 5080 functions and 952 files.
  • It has medium code complexity. Code complexity directly impacts maintainability of the code.
apollo Reuse
Best in #Microservice
Average in #Microservice
apollo Reuse
Best in #Microservice
Average in #Microservice
Top functions reviewed by kandi - BETA

Coming Soon for all Libraries!

Currently covering the most popular Java, JavaScript and Python libraries. See a SAMPLE HERE.
kandi's functional review helps you automatically verify the functionalities of the libraries and avoid rework.

apollo Key Features

Unified management of the configurations of different environments and different clusters Apollo provides a unified interface to centrally manage the configurations of different environments, different clusters, and different namespaces The same codebase could have different configurations when deployed in different clusters With the namespace concept, it is easy to support multiple applications to share the same configurations, while also allowing them to customize the configurations Multiple languages is provided in user interface(currently Chinese and English)

Configuration changes takes effect in real time (hot release) After the user modified the configuration and released it in Apollo, the sdk will receive the latest configurations in real time (1 second) and notify the application

Release version management Every configuration releases are versioned, which is friendly to support configuration rollback

Grayscale release Support grayscale configuration release, for example, after clicking release, it will only take effect for some application instances. After a period of observation, we could push the configurations to all application instances if there is no problem

Authorization management, release approval and operation audit Great authorization mechanism is designed for applications and configurations management, and the management of configurations is divided into two operations: editing and publishing, therefore greatly reducing human errors All operations have audit logs for easy tracking of problems

Client side configuration information monitoring It's very easy to see which instances are using the configurations and what versions they are using

Rich SDKs available Provides native sdks of Java and .Net to facilitate application integration Support Spring Placeholder, Annotation and Spring Boot ConfigurationProperties for easy application use (requires Spring 3.1.1+) Http APIs are provided, so non-Java and .Net applications can integrate conveniently Rich third party sdks are also available, e.g. Golang, Python, NodeJS, PHP, C, etc

Open platform API Apollo itself provides a unified configuration management interface, which supports features such as multi-environment, multi-data center configuration management, permissions, and process governance However, for the sake of versatility, Apollo will not put too many restrictions on the modification of the configuration, as long as it conforms to the basic format, it can be saved. In our research, we found that for some users, their configurations may have more complicated formats, such as xml, json, and the format needs to be verified There are also some users such as DAL, which not only have a specific format, but also need to verify the entered value before saving, such as checking whether the database, username and password match For this type of application, Apollo allows the application to modify and release configurations through open APIs, which has great authorization and permission control mechanism built in

Simple deployment As an infrastructure service, the configuration center has very high availability requirements, which forces Apollo to rely on external dependencies as little as possible Currently, the only external dependency is MySQL, so the deployment is very simple. Apollo can run as long as Java and MySQL are installed Apollo also provides a packaging script, which can generate all required installation packages with just one click, and supports customization of runtime parameters

Vue 3, GraphQL, Apollo - How to re-render query when cache changes?

copy iconCopydownload iconDownload
<template>
  <div v-if="loading">...loading</div>
  <div v-else-if="error">{{ error.message }}</div>
  <div v-else>{{value}}</div>
</template>

<script setup lang="ts">
  import gql from "graphql-tag";
  import { GetValueQuery } from "./ValueComponent.generated";
  import { useQuery, useResult } from "@vue/apollo-composable";

  const GetValue = gql`
    query getValue {
      value
    }
  `;

  function useGetValue() {
    const { result, loading, error } =
      useQuery<GetValueQuery>(GetValue);
    const value = useResult(result, null, (data) => data.value);
    return { value, loading, error };
  }

  const { value, loading, error } = useGetScans();
</script>

Apollo Client &quot;Named export 'remove' not found&quot;

copy iconCopydownload iconDownload
  // nuxt.config.js
  // ...
  build: {
    postcss: {
      postcssOptions: require('./postcss.config.js')
    },
    transpile: [
      '@apollo/client',
      'ts-invariant/process',
    ],
  },
  // ...

I need help on 'Cannot find namespace Kind' issue

copy iconCopydownload iconDownload
$ yarn add @apollo/gateway@~0.46.0

NestJS GraphQL subscriptions not working with `graphql-ws`

copy iconCopydownload iconDownload
subscriptions: {
    'graphql-ws': true,
    'subscriptions-transport-ws': true,
  },

AWS Graphql lambda query

copy iconCopydownload iconDownload
query author(id: '1') {     # Query { author } resolver
  authorName
  books {                   # Author { books(parent) } resolver
    name
    authors {               # Book { author(parent) } resolver
      id
    }
  }
}
// resolver map - passed to the Apollo Server constructor
const resolvers = {
  Query: {
    books,
    authors,
    author,
    book,
  },

  Author: {
    books(parent) { getAuthorBooks(parent); }, // parent is the author - resolver should return a list of books
  },

  Book: {
    authors(parent) { getBookAuthors(parent); }, // parent is the book - resolver should return a list of authors
  },
};
-----------------------
query author(id: '1') {     # Query { author } resolver
  authorName
  books {                   # Author { books(parent) } resolver
    name
    authors {               # Book { author(parent) } resolver
      id
    }
  }
}
// resolver map - passed to the Apollo Server constructor
const resolvers = {
  Query: {
    books,
    authors,
    author,
    book,
  },

  Author: {
    books(parent) { getAuthorBooks(parent); }, // parent is the author - resolver should return a list of books
  },

  Book: {
    authors(parent) { getBookAuthors(parent); }, // parent is the book - resolver should return a list of authors
  },
};

How to use Graphql typescript types in react

copy iconCopydownload iconDownload
type Product = {
  __typename: "Product";
  id: string;
  price: number | null;
  description: string | null;
  name: string | null;
};

const ProductComponent: FC<Product> = ({ name }) => {
  return <p>{name}</p>;
};

export default ProductComponent;
-----------------------
interface ProductComponentProps {
    product: ProductData_allProducts
}


const Product = ({product}: ProductComponentProps) => {
    return (
        <p>{product.name}</p>
    );
};

-----------------------
const Product = ({ product }: { product: ProductData_allProducts }) => {
  return <p>{product.name}</p>;
};
const Product = (props: ProductData_allProducts) => {
  return (
      <p>{product.name}</p>
  );
};
-----------------------
const Product = ({ product }: { product: ProductData_allProducts }) => {
  return <p>{product.name}</p>;
};
const Product = (props: ProductData_allProducts) => {
  return (
      <p>{product.name}</p>
  );
};

Testing React Component with React Router V6

copy iconCopydownload iconDownload
declare function MemoryRouter(
  props: MemoryRouterProps
): React.ReactElement;

interface MemoryRouterProps {
  basename?: string;
  children?: React.ReactNode;
  initialEntries?: InitialEntry[];
  initialIndex?: number;
}
const AllTheProviders = ({ children }) => {
  return (
    <ApolloProvider client={client}>
      <Provider store={store}>
        {children}
      </Provider>
    </ApolloProvider>
  );
};
const customRender = (ui, options) => 
  render(ui, { wrapper: AllTheProviders, ...options });
const { ....queries.... } = customRender(
  <MemoryRouter
    initialEntries={["Test page", "/details/url-param-the-component-needs"]}
  >
    <ComponentUnderTest />
  </MemoryRouter>
);
const { ....queries.... } = customRender(
  <MemoryRouter
    initialEntries={["Test page", "/details/url-param-the-component-needs"]}
  >
    <Routes>
      <Route path="/details/:theParam" element={<ComponentUnderTest />} />
    </Routes>
  </MemoryRouter>
);
-----------------------
declare function MemoryRouter(
  props: MemoryRouterProps
): React.ReactElement;

interface MemoryRouterProps {
  basename?: string;
  children?: React.ReactNode;
  initialEntries?: InitialEntry[];
  initialIndex?: number;
}
const AllTheProviders = ({ children }) => {
  return (
    <ApolloProvider client={client}>
      <Provider store={store}>
        {children}
      </Provider>
    </ApolloProvider>
  );
};
const customRender = (ui, options) => 
  render(ui, { wrapper: AllTheProviders, ...options });
const { ....queries.... } = customRender(
  <MemoryRouter
    initialEntries={["Test page", "/details/url-param-the-component-needs"]}
  >
    <ComponentUnderTest />
  </MemoryRouter>
);
const { ....queries.... } = customRender(
  <MemoryRouter
    initialEntries={["Test page", "/details/url-param-the-component-needs"]}
  >
    <Routes>
      <Route path="/details/:theParam" element={<ComponentUnderTest />} />
    </Routes>
  </MemoryRouter>
);
-----------------------
declare function MemoryRouter(
  props: MemoryRouterProps
): React.ReactElement;

interface MemoryRouterProps {
  basename?: string;
  children?: React.ReactNode;
  initialEntries?: InitialEntry[];
  initialIndex?: number;
}
const AllTheProviders = ({ children }) => {
  return (
    <ApolloProvider client={client}>
      <Provider store={store}>
        {children}
      </Provider>
    </ApolloProvider>
  );
};
const customRender = (ui, options) => 
  render(ui, { wrapper: AllTheProviders, ...options });
const { ....queries.... } = customRender(
  <MemoryRouter
    initialEntries={["Test page", "/details/url-param-the-component-needs"]}
  >
    <ComponentUnderTest />
  </MemoryRouter>
);
const { ....queries.... } = customRender(
  <MemoryRouter
    initialEntries={["Test page", "/details/url-param-the-component-needs"]}
  >
    <Routes>
      <Route path="/details/:theParam" element={<ComponentUnderTest />} />
    </Routes>
  </MemoryRouter>
);
-----------------------
declare function MemoryRouter(
  props: MemoryRouterProps
): React.ReactElement;

interface MemoryRouterProps {
  basename?: string;
  children?: React.ReactNode;
  initialEntries?: InitialEntry[];
  initialIndex?: number;
}
const AllTheProviders = ({ children }) => {
  return (
    <ApolloProvider client={client}>
      <Provider store={store}>
        {children}
      </Provider>
    </ApolloProvider>
  );
};
const customRender = (ui, options) => 
  render(ui, { wrapper: AllTheProviders, ...options });
const { ....queries.... } = customRender(
  <MemoryRouter
    initialEntries={["Test page", "/details/url-param-the-component-needs"]}
  >
    <ComponentUnderTest />
  </MemoryRouter>
);
const { ....queries.... } = customRender(
  <MemoryRouter
    initialEntries={["Test page", "/details/url-param-the-component-needs"]}
  >
    <Routes>
      <Route path="/details/:theParam" element={<ComponentUnderTest />} />
    </Routes>
  </MemoryRouter>
);

Error: GraphQL error: Field 'metafieldsSet' doesn't exist on type 'Mutation' - Shopify GraphQL error

copy iconCopydownload iconDownload
API_VERSION: "2021-10",

Error: You must `await server.start()` before calling `server.applyMiddleware()`

copy iconCopydownload iconDownload
import { ApolloServer } from 'apollo-server-express';
import express from 'express';

async function startApolloServer(typeDefs, resolvers) {
  // Same ApolloServer initialization as before
  const server = new ApolloServer({ typeDefs, resolvers });

  // Required logic for integrating with Express
  await server.start();

  const app = express();

  server.applyMiddleware({
     app,

     // By default, apollo-server hosts its GraphQL endpoint at the
     // server root. However, *other* Apollo Server packages host it at
     // /graphql. Optionally provide this to match apollo-server.
     path: '/'
  });

  // Modified server startup
  await new Promise(resolve => app.listen({ port: 4000 }, resolve));
  console.log(`🚀 Server ready at http://localhost:4000${server.graphqlPath}`);
}
-----------------------
...

const apolloServer = new ApolloServer({
  schema,
  ... // other config
});

// without this, apollo will throw an error.
await apolloServer.start();

const app = express();

apolloServer.applyMiddleware({
  app,
  ... // other config
});

...
-----------------------
server.start().then(res => {
  server.applyMiddleware({ app, path: '/' });
  app.listen({ port }, () => 
    console.log(`Gateway API running at port: ${port}`)
  );  
});

How do I map my Union typed GraphQL response Array in React and Typescript

copy iconCopydownload iconDownload
// I don't know what NodeType is so I'm just using a string for this example
type NodeType = string

interface GetNodesTypeOne {
    readonly getNodesTypeOne: {
        readonly nodes: NodeType[]
    }
}

interface GetNodesTypeTwo {
    readonly getNodesTypeTwo: {
        readonly nodes: NodeType[]
    }
}

type GqlRes = GetNodesTypeOne | GetNodesTypeTwo

const resultOne:GqlRes = {
  getNodesTypeOne: {
    nodes: [ "test" ]
  }
}

const resultTwo:GqlRes = {
  getNodesTypeTwo: {
    nodes: [ "test" ]
  }
}
  const items = data?.getNodesTypeOne.nodes.map(...)
const nodes = "getNodesTypeOne" in data 
    ? data?.getNodesTypeOne?.nodes 
    : data?.getNodesTypeTwo?.nodes
const items = nodes.map(...);
const nodes = blockData.myType === 'type-one'
    ? (data as GetNodesTypeOne)?.getNodesTypeOne?.nodes 
    : (data as GetNodesTypeTwo)?.getNodesTypeTwo?.nodes
const items = nodes.map(...);
const useQueryOne = blockData.myType === 'type-one';

const { data: nodesOne } = useQuery<NodesOneGqlRes, NodesArgs>(NODES_TYPE_ONE,
    {
        variables: {
            customKey: metadata.customKey || 0,
        },
        errorPolicy: 'all',
        notifyOnNetworkStatusChange: true,
        ssr: false,
        skip: !useQueryOne
    }
);

const { data: nodesTwo } = useQuery<NodesTwoGqlRes, NodesArgs>(NODES_TYPE_TWO,
    {
        variables: {
            customKey: metadata.customKey || 0,
        },
        errorPolicy: 'all',
        notifyOnNetworkStatusChange: true,
        ssr: false,
        skip: useQueryOne
    }
);

const nodes = useQueryOne
    ? nodesOne?.getNodesTypeOne?.nodes
    : nodesTwo?.getNodesTypeTwo?.nodes;
const items = (nodes || []).map(...);
-----------------------
// I don't know what NodeType is so I'm just using a string for this example
type NodeType = string

interface GetNodesTypeOne {
    readonly getNodesTypeOne: {
        readonly nodes: NodeType[]
    }
}

interface GetNodesTypeTwo {
    readonly getNodesTypeTwo: {
        readonly nodes: NodeType[]
    }
}

type GqlRes = GetNodesTypeOne | GetNodesTypeTwo

const resultOne:GqlRes = {
  getNodesTypeOne: {
    nodes: [ "test" ]
  }
}

const resultTwo:GqlRes = {
  getNodesTypeTwo: {
    nodes: [ "test" ]
  }
}
  const items = data?.getNodesTypeOne.nodes.map(...)
const nodes = "getNodesTypeOne" in data 
    ? data?.getNodesTypeOne?.nodes 
    : data?.getNodesTypeTwo?.nodes
const items = nodes.map(...);
const nodes = blockData.myType === 'type-one'
    ? (data as GetNodesTypeOne)?.getNodesTypeOne?.nodes 
    : (data as GetNodesTypeTwo)?.getNodesTypeTwo?.nodes
const items = nodes.map(...);
const useQueryOne = blockData.myType === 'type-one';

const { data: nodesOne } = useQuery<NodesOneGqlRes, NodesArgs>(NODES_TYPE_ONE,
    {
        variables: {
            customKey: metadata.customKey || 0,
        },
        errorPolicy: 'all',
        notifyOnNetworkStatusChange: true,
        ssr: false,
        skip: !useQueryOne
    }
);

const { data: nodesTwo } = useQuery<NodesTwoGqlRes, NodesArgs>(NODES_TYPE_TWO,
    {
        variables: {
            customKey: metadata.customKey || 0,
        },
        errorPolicy: 'all',
        notifyOnNetworkStatusChange: true,
        ssr: false,
        skip: useQueryOne
    }
);

const nodes = useQueryOne
    ? nodesOne?.getNodesTypeOne?.nodes
    : nodesTwo?.getNodesTypeTwo?.nodes;
const items = (nodes || []).map(...);
-----------------------
// I don't know what NodeType is so I'm just using a string for this example
type NodeType = string

interface GetNodesTypeOne {
    readonly getNodesTypeOne: {
        readonly nodes: NodeType[]
    }
}

interface GetNodesTypeTwo {
    readonly getNodesTypeTwo: {
        readonly nodes: NodeType[]
    }
}

type GqlRes = GetNodesTypeOne | GetNodesTypeTwo

const resultOne:GqlRes = {
  getNodesTypeOne: {
    nodes: [ "test" ]
  }
}

const resultTwo:GqlRes = {
  getNodesTypeTwo: {
    nodes: [ "test" ]
  }
}
  const items = data?.getNodesTypeOne.nodes.map(...)
const nodes = "getNodesTypeOne" in data 
    ? data?.getNodesTypeOne?.nodes 
    : data?.getNodesTypeTwo?.nodes
const items = nodes.map(...);
const nodes = blockData.myType === 'type-one'
    ? (data as GetNodesTypeOne)?.getNodesTypeOne?.nodes 
    : (data as GetNodesTypeTwo)?.getNodesTypeTwo?.nodes
const items = nodes.map(...);
const useQueryOne = blockData.myType === 'type-one';

const { data: nodesOne } = useQuery<NodesOneGqlRes, NodesArgs>(NODES_TYPE_ONE,
    {
        variables: {
            customKey: metadata.customKey || 0,
        },
        errorPolicy: 'all',
        notifyOnNetworkStatusChange: true,
        ssr: false,
        skip: !useQueryOne
    }
);

const { data: nodesTwo } = useQuery<NodesTwoGqlRes, NodesArgs>(NODES_TYPE_TWO,
    {
        variables: {
            customKey: metadata.customKey || 0,
        },
        errorPolicy: 'all',
        notifyOnNetworkStatusChange: true,
        ssr: false,
        skip: useQueryOne
    }
);

const nodes = useQueryOne
    ? nodesOne?.getNodesTypeOne?.nodes
    : nodesTwo?.getNodesTypeTwo?.nodes;
const items = (nodes || []).map(...);
-----------------------
// I don't know what NodeType is so I'm just using a string for this example
type NodeType = string

interface GetNodesTypeOne {
    readonly getNodesTypeOne: {
        readonly nodes: NodeType[]
    }
}

interface GetNodesTypeTwo {
    readonly getNodesTypeTwo: {
        readonly nodes: NodeType[]
    }
}

type GqlRes = GetNodesTypeOne | GetNodesTypeTwo

const resultOne:GqlRes = {
  getNodesTypeOne: {
    nodes: [ "test" ]
  }
}

const resultTwo:GqlRes = {
  getNodesTypeTwo: {
    nodes: [ "test" ]
  }
}
  const items = data?.getNodesTypeOne.nodes.map(...)
const nodes = "getNodesTypeOne" in data 
    ? data?.getNodesTypeOne?.nodes 
    : data?.getNodesTypeTwo?.nodes
const items = nodes.map(...);
const nodes = blockData.myType === 'type-one'
    ? (data as GetNodesTypeOne)?.getNodesTypeOne?.nodes 
    : (data as GetNodesTypeTwo)?.getNodesTypeTwo?.nodes
const items = nodes.map(...);
const useQueryOne = blockData.myType === 'type-one';

const { data: nodesOne } = useQuery<NodesOneGqlRes, NodesArgs>(NODES_TYPE_ONE,
    {
        variables: {
            customKey: metadata.customKey || 0,
        },
        errorPolicy: 'all',
        notifyOnNetworkStatusChange: true,
        ssr: false,
        skip: !useQueryOne
    }
);

const { data: nodesTwo } = useQuery<NodesTwoGqlRes, NodesArgs>(NODES_TYPE_TWO,
    {
        variables: {
            customKey: metadata.customKey || 0,
        },
        errorPolicy: 'all',
        notifyOnNetworkStatusChange: true,
        ssr: false,
        skip: useQueryOne
    }
);

const nodes = useQueryOne
    ? nodesOne?.getNodesTypeOne?.nodes
    : nodesTwo?.getNodesTypeTwo?.nodes;
const items = (nodes || []).map(...);
-----------------------
// I don't know what NodeType is so I'm just using a string for this example
type NodeType = string

interface GetNodesTypeOne {
    readonly getNodesTypeOne: {
        readonly nodes: NodeType[]
    }
}

interface GetNodesTypeTwo {
    readonly getNodesTypeTwo: {
        readonly nodes: NodeType[]
    }
}

type GqlRes = GetNodesTypeOne | GetNodesTypeTwo

const resultOne:GqlRes = {
  getNodesTypeOne: {
    nodes: [ "test" ]
  }
}

const resultTwo:GqlRes = {
  getNodesTypeTwo: {
    nodes: [ "test" ]
  }
}
  const items = data?.getNodesTypeOne.nodes.map(...)
const nodes = "getNodesTypeOne" in data 
    ? data?.getNodesTypeOne?.nodes 
    : data?.getNodesTypeTwo?.nodes
const items = nodes.map(...);
const nodes = blockData.myType === 'type-one'
    ? (data as GetNodesTypeOne)?.getNodesTypeOne?.nodes 
    : (data as GetNodesTypeTwo)?.getNodesTypeTwo?.nodes
const items = nodes.map(...);
const useQueryOne = blockData.myType === 'type-one';

const { data: nodesOne } = useQuery<NodesOneGqlRes, NodesArgs>(NODES_TYPE_ONE,
    {
        variables: {
            customKey: metadata.customKey || 0,
        },
        errorPolicy: 'all',
        notifyOnNetworkStatusChange: true,
        ssr: false,
        skip: !useQueryOne
    }
);

const { data: nodesTwo } = useQuery<NodesTwoGqlRes, NodesArgs>(NODES_TYPE_TWO,
    {
        variables: {
            customKey: metadata.customKey || 0,
        },
        errorPolicy: 'all',
        notifyOnNetworkStatusChange: true,
        ssr: false,
        skip: useQueryOne
    }
);

const nodes = useQueryOne
    ? nodesOne?.getNodesTypeOne?.nodes
    : nodesTwo?.getNodesTypeTwo?.nodes;
const items = (nodes || []).map(...);
-----------------------
const [invokeQuery1, {loading, data, error}] = useLazyQuery<>(...)
const [invokeQuery2, {loading2, data2, error2}] = useLazyQuery<>(...)

// Run the query every time the condition changes.
useEffect(() => { 
  if (condition) {
    invokeQuery1()
  } else {
    invokeQuery2()
  }
}, [condition])

// Return the desired conditional daa
const {nodes} = useMemo(() => {
  return condition ? data?.getNodesTypeOne : data2?.getNodesTypeTwo
} , 
[condition])
const isNodeTypeOne = (t: unknown): t is GetNodeTypeOne => {
  return (t as GetNodeTypeOne).getNodesTypeOne !== undefined;
};

const { nodes } = isNodeTypeOne(data)
  ? data?.getNodesTypeOne
  : data?.getNodesTypeTwo;

const items = nodes.map((val) => {
  // Your mapping here
})
-----------------------
const [invokeQuery1, {loading, data, error}] = useLazyQuery<>(...)
const [invokeQuery2, {loading2, data2, error2}] = useLazyQuery<>(...)

// Run the query every time the condition changes.
useEffect(() => { 
  if (condition) {
    invokeQuery1()
  } else {
    invokeQuery2()
  }
}, [condition])

// Return the desired conditional daa
const {nodes} = useMemo(() => {
  return condition ? data?.getNodesTypeOne : data2?.getNodesTypeTwo
} , 
[condition])
const isNodeTypeOne = (t: unknown): t is GetNodeTypeOne => {
  return (t as GetNodeTypeOne).getNodesTypeOne !== undefined;
};

const { nodes } = isNodeTypeOne(data)
  ? data?.getNodesTypeOne
  : data?.getNodesTypeTwo;

const items = nodes.map((val) => {
  // Your mapping here
})

Community Discussions

Trending Discussions on apollo
  • Vue 3, GraphQL, Apollo - How to re-render query when cache changes?
  • Apollo Client &quot;Named export 'remove' not found&quot;
  • Duplicate active queries in Apollo Client Devtools
  • I need help on 'Cannot find namespace Kind' issue
  • NestJS GraphQL subscriptions not working with `graphql-ws`
  • AWS Graphql lambda query
  • How to use Graphql typescript types in react
  • Testing React Component with React Router V6
  • Error: GraphQL error: Field 'metafieldsSet' doesn't exist on type 'Mutation' - Shopify GraphQL error
  • Error: You must `await server.start()` before calling `server.applyMiddleware()`
Trending Discussions on apollo

QUESTION

Vue 3, GraphQL, Apollo - How to re-render query when cache changes?

Asked 2022-Mar-31 at 11:33

I would like to know how to build Vue 3 Apollo apps with queries and mutations. I'm familiar with react useQuery hook. It re-renders the component whenever the cached data has been changed (by mutations).

I have tried:

In all cases it just loads the data once and doesnt react to cache data changes.

I undestand that I can build own setup by Apollo client or refetch the queries. I can even invalidate components by its keys. This is not really as elegant as the React useQuery hook is.

I was curious whether there is any ready-made solution and the best practice for smooth graphql operations in Vue 3.

ANSWER

Answered 2022-Mar-31 at 11:33

I have misconfigured the schema and cache update. So the answer is that it works well.

For example:

<template>
  <div v-if="loading">...loading</div>
  <div v-else-if="error">{{ error.message }}</div>
  <div v-else>{{value}}</div>
</template>

<script setup lang="ts">
  import gql from "graphql-tag";
  import { GetValueQuery } from "./ValueComponent.generated";
  import { useQuery, useResult } from "@vue/apollo-composable";

  const GetValue = gql`
    query getValue {
      value
    }
  `;

  function useGetValue() {
    const { result, loading, error } =
      useQuery<GetValueQuery>(GetValue);
    const value = useResult(result, null, (data) => data.value);
    return { value, loading, error };
  }

  const { value, loading, error } = useGetScans();
</script>

Works the described way - the template is re-rendered once data cache changed (by a mutation with the proper result set or by its update function)

So it is not valid question, the bug was in the implementation of cache policy on my side.

Source https://stackoverflow.com/questions/71605607

Community Discussions, Code Snippets contain sources that include Stack Exchange Network

Vulnerabilities

No vulnerabilities reported

Install apollo

You can download it from GitHub, Maven.
You can use apollo like any standard Java library. Please include the the jar files in your classpath. You can also use any IDE and you can run and debug the apollo component as you would do with any other Java program. Best practice is to use a build tool that supports dependency management such as Maven or Gradle. For Maven installation, please refer maven.apache.org. For Gradle installation, please refer gradle.org .

Support

Apollo TeamCommunity GovernanceContributing Guide

DOWNLOAD this Library from

Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
over 430 million Knowledge Items
Find more libraries
Reuse Solution Kits and Libraries Curated by Popular Use Cases

Save this library and start creating your kit

Share this Page

share link
Consider Popular Microservice Libraries
Compare Microservice Libraries with Highest Support
Compare Microservice Libraries with Highest Security
Compare Microservice Libraries with Permissive License
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
over 430 million Knowledge Items
Find more libraries
Reuse Solution Kits and Libraries Curated by Popular Use Cases

Save this library and start creating your kit

  • © 2022 Open Weaver Inc.